Angular 2 --alpha 37 如何在构造函数中获取属性?
Angular 2 --alpha 37 How to get properties in constructor?
这是我的组件,它的 属性 是类型
@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.replace 使用以下代码的构造函数。
constructor(@Attribute('type') type:string) { alert(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.replace 使用以下代码的构造函数。
constructor(@Attribute('type') type:string) { alert(type); }
完成。