【发布时间】:2014-09-17 17:54:39
【问题描述】:
我如何将以下代码形式从 $http.get 更改为 $resource
//The created resource (not using it for now)
hq.factory('LogsOfUser', function ($resource) {
return $resource('/HQ/Graph/GetLoggedinTimes?userName=:userName', {
userName: '@userName'
})
});
//The Controller
var ModalViewLogActionsCtrl = function ($scope, $http, $log, LogsOfUser, $modal) {
$scope.openLogs = function (userName) {
$http.get("/HQ/Graph/GetLoggedinTimes?userName=" + userName).success(function (data) {
var modalInstance = $modal.open({
templateUrl: 'LogView.html',
controller: 'ModalLogViewInstance',
resolve: {
items: function () {
//$scope.items = data;
$log.log(data);
$scope.items = data;
return $scope.items; //return data;
},
userName: function () {
return userName;
}
}
});
}).error(function () {
alert("eror :(");
});;
};
};
【问题讨论】:
-
我正面临在控制器中使用多个资源的问题。如果我使用多个 $http.get,我将无法保持解决方案的清洁,而且我认为这不是正确的方法。仅使用资源资源应该是更清洁的选择
标签: angularjs angularjs-scope angularjs-resource