angular - Angular 2 组件选择器中的条件

标签 angular

使用原生 HTML input 标签,我可以对 type 属性进行绑定(bind),例如,

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

输入元素会根据_field.type的值动态变化

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

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

然后像这样使用它,

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

它不起作用,它不绑定(bind)。

不过,我可以让它与静态值一起工作,

<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

关于angular - Angular 2 组件选择器中的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35573147/

相关文章:

AngularJS2 在管道过滤器后丢失绑定(bind)

angular - 如何在angular2中的同一 Controller 内的另一个函数中调用一个函数

Angular2 - 带动画的动态组件加载

Jquery 和 Bootstrap 4 - 用于调整大小和滚动顶部的导航栏转换

d3.js - 配置 d3 以使用 angular2 和 typescript 的正确方法

angular - 点击事件中的 ngFor 对象

node.js - npm 安装后未找到 Angular2 @angular/forms.js

css - 从 node_modules 到 angular-cli 的自定义字体

angular - 如何将值从模态窗口传递到输入

angular - 将angular2中管道的输出分配给变量