gpt4 book ai didi

angularjs - 将 $resource 注入(inject) Controller

转载 作者:行者123 更新时间:2023-12-02 22:50:00 24 4
gpt4 key购买 nike

我正在尝试创建一个返回 $resource 对象的模块,并且我想将该 $resource 对象注入(inject)到我的其他 Controller 中。这是我的代码

这是返回 $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'}});
});

这些是我想将其注入(inject)的 Controller ......

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) {

我正在将“rest”注入(inject) Controller ,但它给我一个错误,显示“错误:[$injector:unpr] http://errors.angularjs.org/1.2.8/ $injector/unpr?p0=restProvider%20%3C-%20rest 错误( native )”。有什么建议吗?

最佳答案

// 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) { ...

关于angularjs - 将 $resource 注入(inject) Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24900032/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com