0

How can I do console.log(childResult) in the code below? In general where/how can I learn how to access ngRepeat scope(s) variables... NOT those in respective controller (it seems easy)... but esp I want to access the LOOP VARIABLES e.g. childResult in my case. I have read all the guides and tutorials incl stackoverflow questions but I just cannot resolve it.

app.directive("appNamesTyped", ['$http', '$timeout', function ($http, $timeout) {
    //app-names-typed
    return {
        restrict: 'A',
        template: "<li ng-repeat=\"childResult in childrenLookupResults.d.as_typed | orderBy:'fname' | limitTo: limitLookupResults : beginLookupResults\"> </li>",
        link: function (scope, element, attrs) {
            try {
                console.log(childResult);
            } catch(er) {

            }
        }
    };
}]);
user3607612
  • 131
  • 1
  • 11

2 Answers2

1

The way I would do it is by using the childrenLookupResults object and looping through it. It would print the elements without regard to the template. Something like this

link: function (scope, element, attrs) {
    for(var i = 0; i < scope.childrenLookupResults.length; i++){
       console.log(scope.childrenLookupResults[i]);
    }
}

Here's a related question that might be helpful for you: AngularJS: Setting a variable in a ng-repeat generated scope

Community
  • 1
  • 1
Federico Pettinella
  • 1,471
  • 1
  • 11
  • 19
0

Another way:

   link: angular.forEach(scope.childrenLookupResults,function(childrenLookup){
          console.log(childrenLookup);
       });