Arl*_*rie 4 ng-switch angularjs-ng-switch angular
我有一个ngSwitch,用于绑定到下拉列表的模型属性.它没有用,所以我试着简单地对这个值进行硬编码.仍然不起作用,它显示两个 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>
Run Code Online (Sandbox Code Playgroud)
结果在npm服务器上:
mic*_*yks 17
如果需要DEMO:https://plnkr.co/edit/SCZC5Cx9gnQbg1AkkspX? p = preview
更改,
1)
ngSwitch="ACTV" TO [ngSwitch]="'ACTV'"
Run Code Online (Sandbox Code Playgroud)
2)
ngSwitchWhen="CLSD" TO *ngSwitchCase="'CLSD'"
Run Code Online (Sandbox Code Playgroud)
3)
ngSwitchWhen="ACTV" To *ngSwitchCase="'ACTV'"
Run Code Online (Sandbox Code Playgroud)
您使用什么版本的 angular2?在最终(发布)版本中,适合我的语法是:
<div [ngSwitch]="someVariable">
<div *ngSwitchCase="value1">...</div>
<div *ngSwitchCase="value2">...</div>
</div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7796 次 |
| 最近记录: |