简体   繁体   English

保存时不更改的角度布尔值

[英]angular boolean value not changing for the save

I have a scope in my controller. 我的控制器中有一个范围。 Which is this 这是什么

$scope.carprice.active = true

Now in my view i have two radio buttons. 现在在我看来我有两个单选按钮。 Both look like this. 两者都是这样的。

ng-click="carprice.active=true"

ng-click="carprice.active=false"

How do i make the scope change the value? 如何使范围更改值? At the moment its saving down to the database as true even after i've clicked the false option. 目前,即使在我点击了false选项后,它仍然保存到数据库中。

I've tried having the click as a model which hasn't worked either. 我已经尝试将点击作为模型,但也没有用。

Thanks Sam 谢谢山姆

You should not use ngClick for this, you need ngValue directive and bind radio buttons to the same carprice.active model: 你不应该使用ngClick,你需要ngValue指令并将单选按钮绑定到同一个carprice.active模型:

 <script src="https://code.angularjs.org/1.4.8/angular.js"></script> <script>angular.module('demo', [])</script> <div ng-app="demo" ng-init="carprice.active = true;"> <input type="radio" ng-model="carprice.active" ng-value="true"> Active <input type="radio" ng-model="carprice.active" ng-value="false"> Not active <pre>{{ carprice.active }}</pre> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM