我有自定义服务的角度应用程序,在服务中我通过$http
从服务器请求数据,但我无法将服务数据分配到$scope
。这里是代码供参考...
var app = angular.module('jokeRecords');
app.service('AtgService', function($http){
// get method ajax....
this.httpGet = function(url, params){
$http.get(url, {params:params})
.then(function(response) {
console.log(response.data);
return response.data;
}).catch(function(response) {
console.log('get-catch');
console.log(response);
});
};
});
// angular controller...
app.controller('jokeController', function($scope, $http, AtgService) {
var sortColumn = 'id';
var sortDirection = 'asc';
$scope.jokes = AtgService.httpGet("/jokes", {'sortColumn': sortColumn, 'sortDirection': sortDirection });
});
当我在html中使用$scope.jokes
它不显示任何内容。
<tr ng-repeat="x in jokes">
<td>{{x.joke_id}}</td>
<td>{{ x.joke }}</td>
<td>{{ x.submitted_by }}</td>
</tr>
有什么我很想念......
谢谢。