繁体   English   中英

Angular 2组件选择器中的条件

[英]Conditional in Angular 2 Component Selector

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

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

input元素将根据_field.type的值动态变化

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

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

并使用它,像

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

它不起作用,它不绑定。

但是,我可以使用静态值,

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

我想知道如何让它工作?

<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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM