加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 将$resource注入控制器

发布时间:2020-12-17 17:13:34 所属栏目:安全 来源:网络整理
导读:我正在尝试创建一个返回$resource对象的模块,我想将$resource对象注入我的其他控制器.这是我的代码 这是返回$resource的模块…. // module with resourcevar rest = angular.module('rest',['ui.bootstrap','ngResource']).factory('profileAPI',function($r
我正在尝试创建一个返回$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) { ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读