gpt4 book ai didi

AngularJS 选择创建值为 "? object:null ?"的选项,并且在绑定(bind)到 null 时不使用空的默认选项

转载 作者:行者123 更新时间:2023-12-03 23:32:12 24 4
gpt4 key购买 nike

这是代码的样子

<select ng-model="nullableInt">
<option></option>
<option value="0">First option</option>
<option value="1">First option</option>
<option value="2">First option</option>
</select>

当 nullableInt 为 null 时,生成的 html 为
<select ng-model="nullableInt">
<option></option>
<option value="? object:null ?"></option>
<option value="0">First option</option>
<option value="1">First option</option>
<option value="2">First option</option>
</select>

此处转载于 plunkr: http://plnkr.co/edit/05pBEMJppmkrn3nFgYdk?p=info

值得一提的是,我试图避免使用 ng-options ,为 AngularJS 创建一个端点以使用一些实际上不会经常更改的数据(如果有的话)似乎有点矫枉过正。

最佳答案

2017 年 3 月 29 日更新:

正如 Jorge Rodrigues dos Santos 所说,对于新版本的 Angular,这应该以不同的方式处理。以下取自 angular 1.6.3 的当前文档

Optionally, a single hard-coded element, with the value set to an empty string, can be nested into the element. This element will then represent the null or "not selected" option. See example below for demonstration.



https://docs.angularjs.org/api/ng/directive/select

Angular 正在创建一个新选项来表示空值。它没有找到您在 HTML 中提供的选项之一。

要绑定(bind)到 null,请在第一个选项上设置 value="null"
<option value="null"></option>

http://plnkr.co/edit/kzPVu4hiMcP6wA6crGYt?p=preview

关于AngularJS 选择创建值为 "? object:null ?"的选项,并且在绑定(bind)到 null 时不使用空的默认选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23643712/

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