У меня есть угловое приложение с пользовательским сервисом, в сервисе Я запрашиваю данные с сервера через $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 });
});
Когда я использую $scope.jokes
в HTML он не показывает ничего.
<tr ng-repeat="x in jokes">
<td>{{x.joke_id}}</td>
<td>{{ x.joke }}</td>
<td>{{ x.submitted_by }}</td>
</tr>
Что мне не хватает ...
Спасибо.