这是我的组件,它的属性是type
@Component({
selector: 'canvasContainer',
properties: ['type']
})
@View({
templateUrl: "components/canvas/canvas.html",
directives: [Bar, CORE_DIRECTIVES],
styleUrls: ['app.css']
})
export class Canvas
{
constructor() { }
}
这是我的html页面:
<bar type="pie"></bar>
我想像这样在我的构造函数中获取类型pie:
@Component({
selector: 'canvasContainer',
properties: ['type']
})
@View({
templateUrl: "components/canvas/canvas.html",
directives: [Bar, CORE_DIRECTIVES],
styleUrls: ['app.css']
})
export class Canvas
{
constructor() { alert(type); }//this alert is not working
}
使用“ @attribute”在构造函数中获取您的值。
import {Component, View,CORE_DIRECTIVES,Attribute} from 'angular2/angular2';
2.使用以下代码替换您的构造函数。
constructor(@Attribute('type') type:string) { alert(type); }
完毕。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句