我得到一個,對我來說,無意義的錯誤信息,因爲我正在做我說的沒做的事情。
http://errors.angularjs.org/1.6.5/$injector/strictdi?p0=function(labelsResource)
而且它抱怨的代碼是下面的一個,正好(但我刪除的功能labelsResource的實際邏輯):
(function (module, angular) {
"use strict";
var labelsResource = function ($resource, $timeout, salesFlowsContext, applicationConfiguration) { ... };
labelsResource.$inject = ["$resource", "$timeout", "salesFlowsContext", "applicationConfiguration"];
module.factory("labelsResource", labelsResource);
}(
angular.module("common.translation"),
angular
));
我甚至要通過刪除「使用它的工作嚴格「,但錯誤依然存在。我忽略了什麼?
類似問題沒有答案或我爲之工作。
編輯:同時我得知它似乎與我的angular-ui-router升級有關。 我目前使用的版本是0.2.14,但是當我移動到版本1.0.10時出現錯誤。 如果我不動路由器,一切加載的新版本,而是我得到掛角UI路由器許多錯誤:
Error: transition superseded
Error: transition prevented
Error: transition failed
哪個角度-UI-路由器的版本我應該使用這樣我可以成功地讓角度1.6.5工作?
編輯2:
它可能涉及到新的用戶界面路由器。問題就出現在這裏:
$stateProvider
.state({
name: "root",
"abstract": true,
template: "<ui-view/>",
resolve: {
labelsResource: "labelsResource",
codingSchemesResource: "codingSchemesResource",
translation: function (labelsResource) {
return labelsResource.getLabels();
},
codingSchemesTranslation: function (codingSchemesResource) {
return codingSchemesResource.getCodingSchemes();
}
},
controller: "RootController",
controllerAs: "root"
})
當它到達labelsResource和UI路由器試圖做到以下幾點:
// This effectively calls $get() on `$uiRouterProvider` to trigger init (when ng enters runtime)
runBlock.$inject = ['$injector', '$q', '$uiRouter'];
function runBlock($injector, $q, $uiRouter) {
services.$injector = $injector;
services.$q = $q;
// The $injector is now available.
// Find any resolvables that had dependency annotation deferred
$uiRouter.stateRegistry.get()
.map(function (x) { return x.$$state().resolvables; })
.reduce(unnestR, [])
.filter(function (x) { return x.deps === "deferred"; })
.forEach(function (resolvable) { return resolvable.deps = $injector.annotate(resolvable.resolveFn, $injector.strictDi); });
}
它失敗$ injector.annote代碼:
function annotate(fn, strictDi, name) {
var $inject, argDecl, last;
if (typeof fn === 'function') {
if (!($inject = fn.$inject)) {
$inject = [];
if (fn.length) {
if (strictDi) {
if (!isString(name) || !name) {
name = fn.name || anonFn(fn);
}
throw $injectorMinErr('strictdi', '{0} is not using explicit annotation and cannot be invoked in strict mode', name);
}
argDecl = extractArgs(fn);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
arg.replace(FN_ARG, function(all, underscore, name) {
$inject.push(name);
});
});
}
fn.$inject = $inject;
}
} else if (isArray(fn)) {
last = fn.length - 1;
assertArgFn(fn[last], 'fn');
$inject = fn.slice(0, last);
} else {
assertArgFn(fn, 'fn', true);
}
return $inject;
}
我不知道爲什麼。這工作在angularjs 1.5.8和ui-router 0.2.14。
做其他依賴像'salesFlowsContext'&'applicationConfiguration'遵循strictdi? –
是的,還想補充一點,我正在從版本1.5.8移到1.6.5,而我在1.5.8中沒有這個問題。 –