Ser*_*zzo 10 javascript angularjs angular5
我创建了简单的angular5组件HelloComponent
:
var HelloComponent = function () {
};
HelloComponent.annotations = [
new ng.core.Component({
selector: 'hello-world',
template: 'Hello World!'
})
];
Run Code Online (Sandbox Code Playgroud)
接下来,我尝试在angularJS指令中使用此组件,如:
angular.module("app", [])
.directive("helloWorld", ng.upgrade.static.downgradeComponent(HelloComponent))
Run Code Online (Sandbox Code Playgroud)
但是在运行此脚本时出现此错误:
错误:[$ injector:unpr]未知提供者:$$ angularLazyModuleRefProvider < - $$ angularLazyModuleRef http://errors.angularjs.org/1.6.5/ $ injector/unpr?p0 =%24%24angularLazyModuleRefProvider%20%3C-% 20%24%24angularLazyModuleRef
查看带角度5和angularJS的简单示例:http://plnkr.co/edit/dQJ2tgV2MuInT41ucjq1
如何解决这个问题?
附加信息
将组件从v4降级到v1的示例也存在:https://hackernoon.com/angular-v4-hybrid-upgrade-application-73d5afba1e01
但是当我试图用这篇文章重新制作我的应用程序时,我得到另一个错误:
未知提供者:$$ angularInjectorProvider
请参阅第4节的示例:http://plnkr.co/edit/9Oxy0QeSg1FYve0cjGYw
v5的相同示例返回旧错误:
未知提供者:$$ angularLazyModuleRefProvider
请参阅v5的示例:http://plnkr.co/edit/eZScm8U41mGuuHJMjApV
您需要$$UpgradeModule
在应用程序模块中设置依赖关系
改变
angular.module("app", [])
.directive("helloWorld", ng.upgrade.static.downgradeComponent(HelloComponent))
Run Code Online (Sandbox Code Playgroud)
到
var app=angular.module("app", ['$$UpgradeModule']).directive("helloWorld", ng.upgrade.static.downgradeComponent({component:HelloComponent}));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1733 次 |
最近记录: |