Angular 2组件选择器中的条件

时间:2016-02-23 09:07:10

标签: angular

使用原生HTML input标签,我可以对类型属性进行绑定,例如

<input [type]="_field.type">

输入元素将根据_field.type

的值动态更改

但是,如果我有这样的多个组件,

@Component({
  selector: 'field-option[type=options]',
  templateUrl: ''
})

并使用它,

<field-option [type]="_field.type">

它不起作用,它不会绑定。

但是,我可以使用静态值

<field-option [type]="options">

我想知道如何让它发挥作用?

1 个答案:

答案 0 :(得分:2)

<input [type]="_field.type">

有效,因为它是由浏览器处理的。

<field-option [type]="_field.type">

需要Angular支持,但这不是(还是?)实现。

作为一种解决方法,您可以执行类似

的操作
<field-option *ngIf="_field.type='type1'" [type]="type1">
<field-option *ngIf="_field.type='type2'" [type]="type2">

我知道,麻烦: - /

另见https://github.com/angular/angular/issues/6970

相关问题