注射器不工作于角度2.0
我最近开始玩Angular2.我一直试图让注射器工作大约半天,但我仍然无法弄清楚我做错了什么.
为了尽可能简单,我在官方网页上复制了5 Min Quickstart的代码.演示本身工作正常,但是当我尝试使用注射器时,我会发现错误
我的typescript文件 /// <reference path="typings/angular2/angular2.d.ts" /> import {Component,View,bootstrap,} from 'angular2/angular2'; class Names {} // Annotation section @Component({ selector: 'my-app',injectables: [Names] }) @View({ template: '<h1>Hello {{ name }}</h1>' }) // Component controller class MyAppComponent { name: string; constructor(names: Names) { this.name = 'Alice'; } } bootstrap(MyAppComponent); 附:像5 Min Quickstart那样,我使用Traceur,SystemJS和Angular2 alpha(23) 有人知道我失踪了吗?
您的编译器不会向MyAppComponent添加参数属性(从查看您的
pluker).我认为这是问题.如果你添加
MyAppComponent.parameters = [[Names]] 那么一切都会奏效. > Here是你的解决方案. UPD感谢@GrayFox指出正确的方法(见下面的评论):
请参阅TypeScript编译器选项here(您可以在那里找到emitDecoratorMetada). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |