本文介绍了注射剂不是在角工作2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最近,我开始用 Angular2
播放。我一直试图让注射到现在大约半天的工作,但我还是无法弄清楚我在做什么错。
要保持尽可能简单,我复制code从在官方网页。演示本身工作正常,但是当我尝试使用注射剂,我得到一个错误说
My typescript file
/// <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);
P.S. As in the 5 Min Quickstart, I'm using Traceur
, SystemJS
and Angular2 alpha (23)
Does anyone know what I'm missing?
解决方案
Your compiler does not add parameters properties to the MyAppComponent
(from looking at your pluker). I think this is the problem. If you add
MyAppComponent.parameters = [[Names]]
then all will works well.
UPD Thanks to @GrayFox for pointing out the correct way (see the comment bellow):
See TypeScript compiler options here (you can find emitDecoratorMetada
there).
这篇关于注射剂不是在角工作2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!