Angular 为什么ngSwitch没有按预期运行
我根据一些条件显示了一些动态输入元素。我使用ngSwitch指令进行调节。这是我的密码: 模板:Angular 为什么ngSwitch没有按预期运行,angular,typescript,Angular,Typescript,我根据一些条件显示了一些动态输入元素。我使用ngSwitch指令进行调节。这是我的密码: 模板: <div *ngFor="let item of customFieldData"> <div> </div> <label>{{ item.label }}</label> <div [ngSwitch]="item.type"> <div *ngSwitchCase="Text"> &
<div *ngFor="let item of customFieldData">
<div>
</div>
<label>{{ item.label }}</label>
<div [ngSwitch]="item.type">
<div *ngSwitchCase="Text">
<input type="text" placeholder="Enter some text">
</div>
<div *ngSwitchCase="TextArea">
<textarea name="textArea" cols="30" rows="10"></textarea>
</div>
<div *ngSwitchCase="Image">
<input type="file" >
</div>
</div>
我得到的结果是,只有div对应于这个ngSwitchCase,里面什么都没有。
这里我做错了什么。您需要在报价中嵌入值
<div *ngSwitchCase="'Text'">
其余的值也是一样的
您需要将该值嵌入报价中
<div *ngSwitchCase="'Text'">
其余的值也是一样的
只需在您的*ngSwitchCase值中添加单引号即可 html
{{item.label}
如果您遇到任何问题,请务必告诉我。只需在您的*ngSwitchCase值中添加单引号即可 html
{{item.label}
如果你遇到任何问题,一定要告诉我
<div *ngFor="let item of customFieldData">
<div>
</div>
<label>{{ item.label }}</label>
<div [ngSwitch]="item.type">
<div *ngSwitchCase="'Text'">
<input type="text" placeholder="Enter some text">
</div>
<div *ngSwitchCase="'TextArea'">
<textarea name="textArea" cols="30" rows="10"></textarea>
</div>
<div *ngSwitchCase="'Image'">
<input type="file" >
</div>
</div>