How to run code on view updated

36 views
Skip to first unread message

Zoltan Juhasz

unread,
Feb 9, 2012, 10:44:20 AM2/9/12
to ang...@googlegroups.com
Hi,

my controller is using $xhr to get some JSON from the server. The view is then using ng:repeat to display the items of the response. I would need to run some jquery once the view gets updated  (something like $('.selector').button(); ). Is there an easy way to achieve this? 

Thanks,
Zoltan

Witold Szczerba

unread,
Feb 10, 2012, 8:00:49 AM2/10/12
to ang...@googlegroups.com
Create a directive i.e.: "my:button" and use this directive in tags
which are supposed to become a button. So, instead of:

<input type="button" class="someSelector" value="Button text">
plus everywhere scripts like this:
<script> $('.someSelector').button(); </script>


...you will have it done like this instead:
<input type="button" my:button value="Button text">
plus an application-wide definition of a directive.

See documentation/tutorial on how to create your own directive. In
AngularJS 0.10.x (and maybe on 0.9.x), it will be something like this:
angular.directive('my:button', function(expression, compiledElement) {
return function(linkElement) {
linkElement.button();
}
});

Note that the syntax above will be changed (simplified) soon, but the
overall approach will remain.

Regards,
Witold Szczerba

> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/angular?hl=en.

ThomasBurleson

unread,
Feb 10, 2012, 9:16:08 AM2/10/12
to AngularJS
@Witold
FYI

Angular v0.10.7.x no longer supports angular.directive().

For v0.10.6 and earlier: angular.directive()
For v0.10.7.x angular.module().directive()...

- ThomasB

On Feb 10, 7:00 am, Witold Szczerba <pljosh.m...@gmail.com> wrote:
> Create a directive i.e.: "my:button" and use this directive in tags
> which are supposed to become a button. So, instead of:
>
> <input type="button" class="someSelector" value="Button text">
> plus everywhere scripts like this:
> <script> $('.someSelector').button(); </script>
>
> ...you will have it done like this instead:
> <input type="button" my:button value="Button text">
> plus an application-wide definition of a directive.
>
> See documentation/tutorial on how to create your own directive. In
> AngularJS 0.10.x (and maybe on 0.9.x), it will be something like this:
> angular.directive('my:button', function(expression, compiledElement) {
>   return function(linkElement) {
>     linkElement.button();
>   }
>
> });
>
> Note that the syntax above will be changed (simplified) soon, but the
> overall approach will remain.
>
> Regards,
> Witold Szczerba
>
Reply all
Reply to author
Forward
0 new messages