我收到了一个荒谬的错误信息,因为我正在按照我说的那样做。
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
));
我甚至尝试通过删除“use strict”来使其工作,但错误仍然存在。我在俯瞰什么?
类似的问题没有答案或对我有用。
编辑:与此同时,我了解到它似乎与我对angular-ui-router的升级有关。 我目前正在使用0.2.14版本,但是当我转到版本1.0.10时,我得到了错误。 如果我没有移动到更新版本的路由器,一切都加载,但我得到很多错误链接到angular-ui-router:
Error: transition superseded
Error: transition prevented
Error: transition failed
我应该使用哪个版本的Angular-ui路由器,以便我能成功地使角度1.6.5工作?
编辑2:
这可能与新的ui路由器有关。问题出现在这里:
$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-router尝试执行以下操作时:
// 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。
答案 0 :(得分:0)
我通过类似的问题找到了我的问题的解决方案: angular-ui-router not resolving injected parameters
这不是同一个问题,但在看到上述问题的答案后,简单的解决方案终于打动了我。不敢相信花了半天才能通过我...
我只需像其他任何其他功能那样注入,例如在制作新模块时。
以下代码的解决方案:
Containers: 11
Running: 11
Paused: 0
Stopped: 0
Images: 8
Server Version: 17.09.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 76
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.4.0-97-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.695GiB
Name: egmintel-desktop
ID: VB22:IXWI:GY6D:QPM4:SPHX:HYUP:OQN7:ZM55:LLKE:P3UU:XK7F:26TH
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
My docker-compose version:
docker-compose version 1.16.1, build 6d1ac21
以下是
resolve: {
labelsResource: "labelsResource",
codingSchemesResource: "codingSchemesResource",
translation: function (labelsResource) {
return labelsResource.getLabels();
},
codingSchemesTranslation: function (codingSchemesResource) {
return codingSchemesResource.getCodingSchemes();
}
}