当我在服务中执行http.get时,我无法使用{{gs}}更新视图中的$ scope.gs变量。我尝试阅读一些答案,但他们似乎暗示了这种方法。请帮助...
我的服务方法如下:
app.service('myService', function($http, $rootScope) {
this.getData = function(key){
return $http.get('/myapp/stocklist/AMZN').
then(function(data) {
return data;
});
}
//return this;
});
我的控制器:
app.controller('graph', ['$scope', '$http', 'myService', function($scope,$http, myService){
myService.getData($scope.mySelected).then(function(codes){
$scope.gs= codes;
});
}]);
我不知道我是否应该使用工厂,而不是服务于这一点。你能咨询一下吗?
控制台错误??? – TKHN