我有一段看起来像这样的代码
@Component({
selector: 'control-messages',
inputs: ['controlName: control'],
template: `<div *ngIf="errorMessage !== null">{{errorMessage}}</div>`
})
如何将其更改为@Input()属性装饰器。
答案 0 :(得分:2)
应该像:
import {Component, OnInit, Input} from 'angular2/core';
@Component({
selector: 'control-messages',
template: `<div *ngIf="errorMessage !== null">{{errorMessage}}</div>`
})
export class YourClass{
@Input()
controlName: control;
constructor() {
}
ngOnInit() {
}
}
答案 1 :(得分:2)
请参阅https://angular.io/docs/ts/latest/guide/template-syntax.html#!#inputs-outputs
%label{:for=>"name", } Name:
%input{:id=>"name", :type=>"text", :required => true}
%br
%label{:for=>"email", } Email address:
%input{:id=>"email", :type=>"email", :required => true}
所以如果inputs:['controlName: control'] // propertyName: alias
@Input('control') controlName: optional_type; // @Input('alias') propertyName:type
是一个字符串:
controlName