javascript - Is possible to access angularjs $scope from within a $scope.$apply call -
is possible access $scope variables , functions within $scope.$apply call?
below bogus example demonstrate point. shown, somefunctionwithacallbackparam called when controller starts , parameter used callback when function completes.
within $scope.$apply, $scope variables , functions visible? if not how 1 access $scope?
angular .module('mycontroller') .controller('examplecontroller', ['$scope', function($scope) { $scope.data = []; somefunctionwithacallbackparam(function(mylist) { $scope.$apply(function() { (var = 0; < mylist.length; i++) { // $scope visible here?? $scope.additem(mylist[i]); } }); } $scope.additem(item) { // stuff $scope.data.push(item); } }]);
yes. best practice however, should assign variables , functions scope going use in view. try , separate view , controller variables , functions.
//controller variable var blocks = []; //scope variable $scope.buyers = []; //controller function var addblock = function(block) { blocks.push(block); } //scope function $scope.blah = function() { //do stuff }
Comments
Post a Comment