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.
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:
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.