當我在服務中執行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