There are a few ways to go about this. Without knowing the details of what
you're end game is, I can offer two solutions off the bat:
1) directives - core to angular, you can hang a directive attribute off of
the repeating item:
<li ng-repeat="item in items" my-directive-name></li>
app.directive("myDirectiveName", [function() {
return {
restrict: "A",
scope: true, // this keeps all the logic and variables locally
scoped to the individual element
controller: function($scope) {
// do some data manipulation here if you need to
var myFunctionName = function() {
// do something
}
// execute the function - keep in mind this will fire as soon as
the directive is loaded, if you have any other ajax that is getting data
you may have a timing issue
myFunctionName();
},
link: function(scope, element, attrs) {
// do DOM manipulation here with jQuery if you need
// element is the "LI"
}
}
});
2) if your function is simple and already baked into your controller for
this view, you can call ng-init="myFunction()" on the "LI":
<li ng-repeat="item in items" ng-init="myFunction()"></li>
----
Again without knowing more of the details, IMO directives are the best way
to handle things when it comes to enacting things from a view.
Cheers
On Friday, March 14, 2014 2:25:20 AM UTC-4, Yash Ganthe wrote:
>
> Hi,
>
> I am aware that Angular is used for generating HTML. Setting $scope.items
> to an array will cause <li ng-repeat> to generate multiple LI items.
>
> In my case, for every element of items, I would like to invoke a
> Javascript function. The Javascript then adds somthing to the DOM. <script
> ng-repeat> is not allowed by Angular. What is the best way to invoke a
> javascript repeatedly using Angular?
>
> Thanks,
> Yash
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.