【发布时间】:2018-01-04 06:49:28
【问题描述】:
我是 Angular 的新手,无论我们选择 type=input 还是 type=select,我都在尝试使用 ng-if 条件,如果我们选择 type=select,则将呈现选择 html,否则将呈现输入类型 这是我的代码
template: `<div *ngIf="type='input'">
<div class='investecField textField'>
<div class='investecFieldIn'>
<label>
<span>{{value}}</span>
<input type="text" value="{{valueInput}}">
</label>
</div>
</div>
</div>`
+
`<div *ngIf="type='select'">
<div class='investecField selectField'>
<div class='investecFieldIn'>
<label>
<span>{{selectValue}}</span>
<strong><i class='fa fa-sort-desc' aria-hidden='true'></i></strong>
<select>
<option></option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>
</label>
</div>
</div>
</div>`
})
export class investecFieldComponent implements OnInit {
@Input()
set selectValue(name: string) {
};
@Input() value: string;
@Input() valueInput: string;
constructor(private elem: ElementRef, private renderer: Renderer2) {
}
ngOnInit() {
}
}
在 html 中是:
<investec-field [ngIf]="type=='input'"
value="User Name"
valueInput="">
</investec-field>
但我在控制台中遇到错误 错误:模板解析错误: 解析器错误:绑定不能在 ng:///AppModule/investecFieldComponent.html@0:5 ("]*ngIf="type='input'">
中的 [type='input'] 的第 6 列包含分配>【问题讨论】:
标签: angular typescript angular2-directives