gpt4 book ai didi

javascript - ng-if 为 0 时的 Angular 问题

转载 作者:行者123 更新时间:2023-11-28 18:10:07 25 4
gpt4 key购买 nike

ng-if="表达式值为 0" 时,我遇到了一个问题,它不起作用,正如人们所认为的那样。

这里是骗子的链接:http://plnkr.co/edit/dILXSIHHzvuv1nhbxdga?p=info

更改选择时,我使用模型值来显示特定的文本框。

<select ng-model="location.locationSchedule.scheduleType" 
ng-options="schedule.id as schedule.name for schedule in scheduleTypes track by schedule.id">
<option value="">Choose a Schedule Type</option>
</select>

以及输入字段

<input ng-model="location.locationSchedule.frequency" 
placeholder="Enter Week No."
ng-if="location.locationSchedule.scheduleType == 0"/>
<input ng-model="location.locationSchedule.frequency"
placeholder="Enter Week No."
ng-if="location.locationSchedule.scheduleType == 1"/>

如果location.locationSchedule.scheduleType == 1它显示特定的文本框,但当它为0时则不显示

最佳答案

那是因为父 ngIf

替换

ng-if="location.locationSchedule.scheduleType != ''"

ng-if="location.locationSchedule.scheduleType !== ''"

或者任何更合适的东西(参见 Implied string comparison, 0='', but 1='1' )

关于javascript - ng-if 为 0 时的 Angular 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41814315/

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