我正在尝试创建一个返回$ resource对象的模块,我想将$ resource对象注入我的其他控制器。这是我的代码
这是返回$ resource ....
的模块// module with resource
var rest = angular.module('rest', ['ui.bootstrap','ngResource'])
.factory('profileAPI', function($resource) {
// get the user id
$scope.userid = sessionStorage["cerestiuserid"];
// json we get from server
$scope.apicall = sessionStorage["cerestihome"];
return $resource($scope.apicall + "/api/userprofile/", {Userid:$scope.userid}, {'post':{method: 'POST'}});
});
这些是我想要注入的控制器......
var profile = angular.module('profile', ['ui.bootstrap','ngResource', 'rest']);
profile.controller("profileController", ["$scope", "$resource", 'rest', function($scope, $resource, rest) {
var route = angular.module('route', ["ui.router"])
route.controller('editController', ["$scope", "$resource", 'rest', function($scope, $resource, infos) {
我正在向控制器注入“休息”,但是它给了我一个错误,上面写着“错误:[$ injector:unpr] http://errors.angularjs.org/1.2.8/ $ injector / unpr?p0 = restProvider%20%3C-%20rest 在错误(本机)“。任何建议?
答案 0 :(得分:3)
// injecting 'rest' module
var profile = angular.module('profile', ['ui.bootstrap','ngResource', 'rest']);
//injecting profileAPI factory
profile.controller("profileController", ["$scope", "$resource", 'profileAPI',
function($scope, $resource, profileAPI) { ...
//injecting 'rest' module
var route = angular.module('route', ["ui.router",'ngResource','route'])
//injecting factory
route.controller('editController', ["$scope", "$resource", 'infos','profileAPI',
function($scope, $resource, infos,profileAPI) { ...