Angular4 ng-if 条件是 select 类型 "input" 还是 "select"
Angular4 ng-if condition whether select type of "input" or "select"
我是 angular 的新手,我正在尝试使用 ng-if 条件,无论我们 select type=input 还是 type=select,如果我们 select type=select then 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'">
您应该使用 ===
签入您的模板
`<div *ngIf="type==='input'">
我是 angular 的新手,我正在尝试使用 ng-if 条件,无论我们 select type=input 还是 type=select,如果我们 select type=select then 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'">
您应该使用 ===
签入您的模板
`<div *ngIf="type==='input'">