Error: [$injector:unpr] Unknown provider - while migrating AngularJS1 to Angular6
Error: [$injector:unpr] Unknown provider - while migrating AngularJS1 to Angular6
我正在尝试将用 AngularJS1 编写的组件升级到 Angular6。在我的示例中,我通过扩展放置在文件夹 "directive-wrappers" 下的“UpgradeComponent”来为所有现有的 AngularJS1 组件提供包装器。
加载应用程序时出现控制台错误
Error: [$injector:unpr] Unknown provider: testDirective2DirectiveProvider <- testDirective2Directive
https://errors.angularjs.org/1.7.8/$injector/unpr?p0=testDirective2DirectiveProvider%20%3C-%20testDirective2Directive
at eval (angular.js:138)
at eval (angular.js:4924)
at Object.getService [as get] (angular.js:5084)
at eval (angular.js:4929)
at Object.getService [as get] (angular.js:5084)
at Function.UpgradeHelper.getDirective (upgrade_helper.ts:56)
at new UpgradeHelper (upgrade_helper.ts:52)
at TestDirective2Wrapper.UpgradeComponent (upgrade_component.ts:106)
at new TestDirective2Wrapper (TestDirective2Wrapper.ts:27)
at createClass (provider.ts:265) "<app-root _nghost-c0="">"
为了在线模拟相同的应用程序,我在 stackblitz
中创建了相同的 angularjs 指令及其包装器
docsSampleDirective.js
文件有问题。
您已经在那里初始化了 AngularJS 模块,而您已经在 [ 中初始化了 testApp
模块。 =13=] 文件。只需从那里摆脱依赖数组:
angular
.module("testApp")
.controller("Controller", [
"$scope",
function($scope) {
$scope.customer = {
name: "Naomi",
address: "1600 Amphitheatre"
};
}
])
.directive("docsSimpleDirective", function() {
return {
template: "Name: {{customer.name}} Address: {{customer.address}}"
};
});
Here's a Working Sample StackBlitz for your ref.
我正在尝试将用 AngularJS1 编写的组件升级到 Angular6。在我的示例中,我通过扩展放置在文件夹 "directive-wrappers" 下的“UpgradeComponent”来为所有现有的 AngularJS1 组件提供包装器。
加载应用程序时出现控制台错误
Error: [$injector:unpr] Unknown provider: testDirective2DirectiveProvider <- testDirective2Directive
https://errors.angularjs.org/1.7.8/$injector/unpr?p0=testDirective2DirectiveProvider%20%3C-%20testDirective2Directive
at eval (angular.js:138)
at eval (angular.js:4924)
at Object.getService [as get] (angular.js:5084)
at eval (angular.js:4929)
at Object.getService [as get] (angular.js:5084)
at Function.UpgradeHelper.getDirective (upgrade_helper.ts:56)
at new UpgradeHelper (upgrade_helper.ts:52)
at TestDirective2Wrapper.UpgradeComponent (upgrade_component.ts:106)
at new TestDirective2Wrapper (TestDirective2Wrapper.ts:27)
at createClass (provider.ts:265) "<app-root _nghost-c0="">"
为了在线模拟相同的应用程序,我在 stackblitz
中创建了相同的 angularjs 指令及其包装器docsSampleDirective.js
文件有问题。
您已经在那里初始化了 AngularJS 模块,而您已经在 [ 中初始化了 testApp
模块。 =13=] 文件。只需从那里摆脱依赖数组:
angular
.module("testApp")
.controller("Controller", [
"$scope",
function($scope) {
$scope.customer = {
name: "Naomi",
address: "1600 Amphitheatre"
};
}
])
.directive("docsSimpleDirective", function() {
return {
template: "Name: {{customer.name}} Address: {{customer.address}}"
};
});
Here's a Working Sample StackBlitz for your ref.