gpt4 book ai didi

javascript - 添加工厂时出现错误 : [$injector:unpr]

转载 作者:行者123 更新时间:2023-11-28 17:46:35 28 4
gpt4 key购买 nike

尝试添加一个简单工厂并收到错误:

Error: [$injector:unpr] http://errors.angularjs.org/1.4.6/$injector/unpr?p0=subfactoryProvider%20%3C-%20subfactory%20%3C-%20authService%20%3C-%20AuthorizationInterceptor%20%3C-%20%24http%20%3C-%20%24templateRequest%20%3C-%20%24compile

我添加了一个脚本标签:

<script src="app/subfactory.js"></script>

子工厂定义如下:

(function () {
//'use strict';

angular
.module('app')
.factory('subfactory', subfactory);

function subfactory() {

var subValue = {};
return {
set: set,
get: get
};

function get() {
return subValue;
}

function set(value) {
subValue = value;
}
}

});

在authService中使用:

(function () {
//'use strict';

angular
.module('app')
.factory('authService', authService);

authService.$inject = ['subfactory'];

function authService(subfactory) {

// removed code for brevity

mgr.getUser().then(function (user) {
if (user) {
var idToken = user.id_token;
var dataIdToken = getDataFromToken(idToken);
subfactory.set(dataIdToken.sub);
} else {
//console.log("User not logged in");
}
});

我还有调用 authService 的 AuthorizationInterceptor:

app.factory("AuthorizationInterceptor", ['$q', '$injector', '$rootScope', '$window', 'authService', function ($q, $injector, $rootScope, $window, authService) {

请问如何解决此错误?

编辑:

<script src="app/app.js"></script>
<script src="app/authService.js"></script>
<script src="app/subfactory.js"></script>

app.factory("AuthorizationInterceptor"...app.js

中定义

该错误消息是 F12 控制台中的唯一消息。

最佳答案

尝试翻转声明文件的顺序,如下所示:

// only define your module here
<script src="app/app.js"></script>

// define your factories
<script src="app/subfactory.js"></script>
<script src="app/authService.js"></script>

// define your authorization factory here just like the previous two
<script src="app/Authorization.js"></script>

关于javascript - 添加工厂时出现错误 : [$injector:unpr],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46583700/

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