맞춤 서비스를 제공하는 각도 서비스가 있습니다. 서버에서 $http
을 통해 데이터를 요청하지만 서비스 데이터를 $scope
에 할당 할 수 없습니다. 내가 아무것도 표시되지 않습니다 HTML로 $scope.jokes
을 사용하면 여기에 ...
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 });
});
참조 코드입니다.
<tr ng-repeat="x in jokes">
<td>{{x.joke_id}}</td>
<td>{{ x.joke }}</td>
<td>{{ x.submitted_by }}</td>
</tr>
내가 놓친 게 아무것도 ...
는 감사가있다.