angularjs – 将$resource注入控制器

前端之家收集整理的这篇文章主要介绍了angularjs – 将$resource注入控制器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试创建一个返回$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','ngResource','rest']);

profile.controller("profileController",["$scope","$resource",'rest',function($scope,$resource,rest) { 

var route = angular.module('route',["ui.router"])

route.controller('editController',infos) {

我正在向控制器注入“休息”,但它给了我一个错误,上面写着“错误:[$injector:unpr] http://errors.angularjs.org/1.2.8/ $injector / unpr?p0 = restProvider < - rest
    在错误(本机)“.任何建议?

解决方法

// injecting 'rest' module 
var profile = angular.module('profile','rest']); 

//injecting profileAPI factory
profile.controller("profileController",'profileAPI',profileAPI) { ...

//injecting 'rest' module 
var route = angular.module('route',["ui.router",'route']) 

//injecting factory
route.controller('editController','infos',infos,profileAPI) { ...

猜你在找的Angularjs相关文章