javascript - Scope is not being applied to the scope variables -
i have snippet of code in controller:
$scope.$on('$ionicview.enter', function() { $scope.nodeid = $stateparams.studynoderef; studies.fetchcollection($scope.nodeid).then(function(data){ $scope.y = angular.fromjson(data.list); $scope.collections = angular.fromjson($scope.y[0].collections); console.log($scope.collections); }) });
the reason have $scope.$on because want nodeid update every time enter view can update collections. before had $scope.$on function , had study.fetchcollection function able iterate through collections in template this:
<ion-list ng-controller="studyctrl"> <ion-item ng-repeat="collection in collections" nav-clear menu-close ng-click="go('app.studies')" class="item item-icon-left brand-base-text-color"> <i class="icon ion-ios-paper"></i> {{collection.name}} </ion-item>
but displays nothing. if try display {{collections}} shows nothing. console returns $scope.collections list of objects don't think $scope being applied why {{collections}} blank , not sure how use $scope.$apply() in context. appreciate if tell me how fix this
one of ways overcome create function , call in within controller , since controller attached view updated every time enter view .
$scope.onload = function() { $scope.nodeid = $stateparams.studynoderef; studies.fetchcollection($scope.nodeid).then(function(data){ $scope.y = angular.fromjson(data.list); $scope.collections = angular.fromjson($scope.y[0].collections); console.log($scope.collections); }) } $scope.onload();
Comments
Post a Comment