[英]angular boolean value not changing for the save
我的控制器中有一個范圍。 這是什么
$scope.carprice.active = true
現在在我看來我有兩個單選按鈕。 兩者都是這樣的。
ng-click="carprice.active=true"
ng-click="carprice.active=false"
如何使范圍更改值? 目前,即使在我點擊了false選項后,它仍然保存到數據庫中。
我已經嘗試將點擊作為模型,但也沒有用。
謝謝山姆
你不應該使用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.