2016-09-26 7 views
0

console.log(childResult)を以下のコードでどうすればいいですか?一般的にどこで/どのようにngRepeatスコープの変数にアクセスするかを学ぶことができます...それぞれのコントローラのものではありません(それは簡単です)...しかし、私はループの変数にアクセスしたいです。私の場合はchildResultです。私はstackoverflowの質問を含むすべてのガイドとチュートリアルを読んだが、私はそれを解決することはできません。角度NgRepeatでループ変数にアクセスする方法

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) { 

      } 
     } 
    }; 
}]); 
+0

ます "はconsole.log(scope.childResult)" を試してみました – Aparna

答えて

1

私が行う方法は、childrenLookupResultsオブジェクトを使用してループすることです。テンプレートに関係なく要素を出力します。この

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

ようなものがここにあなたのための役に立つかもしれません関連の質問です:AngularJS: Setting a variable in a ng-repeat generated scope

0

別の方法:

link: angular.forEach(scope.childrenLookupResults,function(childrenLookup){ 
      console.log(childrenLookup); 
     }); 
関連する問題