javascript - Array attribute of scope in directive is emptied upon reference -
my directive looks this:
angular.module('app') .directive('chart', function () { return { template: '<div class="chart"></div>', restrict: 'e', replace: 'true', scope: { data: '=' }, link: function (scope, element, attrs) { console.log(scope); console.log(scope.data); } };});
and gets passed array controller in view.
<chart data="array"></chart>
the console output looks follows:
scope {...} $id: "006" $parent: child $root: scope ... data: array[1] 0: 10300 length: 1 __proto__: array[0] this: scope __proto__: object
and
[]
when scope object displayed in console has 'data' attribute length 1 , entry '10300', when scope.data printed empty array '[]'.
why? confused :)
the problem array initialized in controller [] , filled through function called $watch. reason 2 console outputs seem print different states of controller. solution call function once in controller initialize array values straight away.
Comments
Post a Comment