javascript - Reference $scope variables from within $http request angular -
i new angularjs , having hard time trying figure out issue.
basically, using mill request info our application. when mill returns promise, hoping info within returned promise defined in our scope, able used, returning text on page.
for example: have defined $scope.name in our controller:
app.controller('accountcontroller',function($scope,account) { $scope.name = 'abby'; $scope.news = []; account.getsnapshot().success(function(data) { $scope.news.push(data); }); });
so mill (getsnapshot) homecoming "hello {{name}}" $http request follows:
app.factory('account',function($http) { homecoming { getsnapshot : function() { homecoming $http.get('data.php'); } } });
is possible allow mill access /use {{name}} $scope?
you need utilize internal angular $interpolate
service:
app.controller('accountcontroller', function($scope, $interpolate, account) { $scope.name = 'abby'; $scope.news = []; account.getsnapshot().success(function(data) { var text = $interpolate(data)($scope); $scope.news.push(text); }); });
javascript angularjs
No comments:
Post a Comment