gpt4 book ai didi

Angular2 ngSwitch 不工作

转载 作者:太空狗 更新时间:2023-10-29 17:41:32 24 4
gpt4 key购买 nike

我有一个 ngSwitch 用于绑定(bind)到下拉列表的模型属性。它不起作用,所以我尝试简单地对值进行硬编码。仍然不起作用,它显示两个 div。我究竟做错了什么?如果这很明显,请提前致歉,我是 Angular2 的新手。

我的 html 模板:

      <!-- display closed date if status is closed, otherwise display active date -->
<div ngSwitch="ACTV">
<div class="form-group row" ngSwitchWhen="CLSD">
<label for="closeDt" class="col-md-4 form-control-label text-md-right">
Close Date
<span class="help-block">Required field</span>
</label>
<div class="col-md-4 col-xs-12">
<datetime [timepicker]="false" [(ngModel)]="date2" id="close-date" name="close-date"></datetime>
</div>
</div>
<div class="form-group row" ngSwitchWhen="ACTV">
<label for="issueDt" class="col-md-4 form-control-label text-md-right">
Active Date
<span class="help-block">Required field</span>
</label>
<div class="col-md-4 col-xs-12">
<datetime [timepicker]="false" [(ngModel)]="date2" id="active-date" name="active-date"></datetime>
</div>
</div>
</div>

npm 服务器上的结果:

enter image description here

最佳答案

如果需要演示:https://plnkr.co/edit/SCZC5Cx9gnQbg1AkkspX?p=preview

改变,

1)

ngSwitch="ACTV"        TO     [ngSwitch]="'ACTV'"

2)

ngSwitchWhen="CLSD"    TO     *ngSwitchCase="'CLSD'"

3)

ngSwitchWhen="ACTV"    To     *ngSwitchCase="'ACTV'"

关于Angular2 ngSwitch 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40180304/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com