Angular2:输入绑定

Angular2:输入绑定,angular,Angular,我正在尝试将输入与此处定义的组件绑定: 但组件名称从未显示 我甚至尝试执行console.log,但它显示: 组件名称未定义 } 我错过了什么 谢谢您的输入在构造函数中还不可用。试试这个f.e @Input set componentName(value: string) { if(value != null && value != undefined) { this._componentName = value; console.log(this._compon

我正在尝试将输入与此处定义的组件绑定:

但组件名称从未显示

我甚至尝试执行console.log,但它显示:

组件名称未定义

}

我错过了什么


谢谢

您的输入在构造函数中还不可用。试试这个f.e

@Input set componentName(value: string) { 
  if(value != null && value != undefined) {
    this._componentName = value; console.log(this._componentName); 
  }
}

_componentName: string

通过这种方式,您可以在
集合中的
if
语句中调用方法。您的输入在构造函数中还不可用。试试这个f.e

@Input set componentName(value: string) { 
  if(value != null && value != undefined) {
    this._componentName = value; console.log(this._componentName); 
  }
}

_componentName: string

这样,您就可以在
集合中的
if
语句中调用方法。如果您的输入是字符串,则需要丢失“[]”

componentName="componentname"

如果输入是字符串,则需要丢失“[]”

componentName="componentname"
@Input set componentName(value: string) { 
  if(value != null && value != undefined) {
    this._componentName = value; console.log(this._componentName); 
  }
}

_componentName: string
componentName="componentname"