Angular, boolean value in a select box(选择框中的角度布尔值)
问题描述
我想使用选择将布尔值设置为 true 或 false,这是我的代码:
I want to set a boolean value to true or false using a select here is my code:
<select class="span9" ng-model="proposal.formalStoryboard">
<option value="false">Not Included</option>
<option value="true">Included</option>
</select>
值 (proposal.formalStoryboard) 已正确设置为 true 或 false 但当该值已分配时,更改不会反映在选择框上.
The value (proposal.formalStoryboard) is set properly to true or false but the change are not reflected on the select box when the value is already assigned.
我尝试了 ng-value="true" 和 ng-value="false" 而不仅仅是 value,但效果不佳.
I tried ng-value="true" and ng-value="false" instead of just value but it's not working as well.
推荐答案
评论者指出我原来的解决方案并没有像声称的那样工作.我已更新答案以反映下面其他人给出的正确答案(我无法删除已接受的答案).
Commentors have pointed out that my original solution did not work as claimed. I have updated the answer to reflect the correct answer given by others below (I cannot delete an accepted answer).
对于 Angular 1.0.6,请考虑以下 HTML:
For Angular 1.0.6, consider this HTML:
<div ng-app="">
<div ng-controller="MyCntrl">
<select ng-model="mybool"
ng-options="o.v as o.n for o in [{ n: 'Not included', v: false }, { n: 'Included', v: true }]">
</select>
<p>
Currently selected: <b>{{ mybool }}</b> opposite: {{ !mybool }}
</p>
</div>
</div>
还有这个 JavaScript:
And this JavaScript:
function MyCntrl($scope) {
$scope.mybool = true;
}
这是一个适用于 Angular 1.0.6 的 DEMO,这是一个有效的 DEMO,略有不同.
Here is a working DEMO for Angular 1.0.6 and here is a working DEMO for Angular 1.3.14, which is slightly different.
这篇关于选择框中的角度布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:选择框中的角度布尔值


- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 400或500级别的HTTP响应 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01