Sam Roberts
Sam Roberts

Reputation: 185

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.

I've tried having the click as a model which hasn't worked either.

Thanks Sam

Upvotes: 1

Views: 683

Answers (1)

dfsq
dfsq

Reputation: 193291

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>

Upvotes: 3

Related Questions