angularjs - angular scope variable has no data -
i'm pretty new angular js seems simple code should work. here html:
<body ng-app="myhomepage"> <div ng-controller="redditload"> {{a}} <ul> <li ng-repeat="article in a"> {{article.data.title}} </li....
and here angualr_app.js:
var app = angular.module('myhomepage', []) function redditload($scope){ $.getjson("http://www.reddit.com/.json?jsonp=?", function(data) { var data_array = []; $.each(data.data.children, function(i,item){ data_array.push(item); }); console.log(data_array); $scope.a = data_array; }); }
what doing wrong? console.log(data_array); showing correct values data wont seem passed template.
the getjson callback isn't executed in angular context angular doesn't know changes , won't refresh bindings. when code called external source (like jquery event ), have encapsulate scope changes in $apply call:
$scope.$apply(function{ $scope.a = data_array; }
Comments
Post a Comment