1

I have a checkbox which has to be checked only if a property is false. I have the next html:

 <input type="checkbox" ng-model="list.IsProject" ng-checked="list.IsProject==false"  name="IsProject" id="IsProject" ng-change="saveItem(list, 'IsProject')"> Not Shared

After checking/unchecking I need to update the database and this has not the expected behaviour. Basically, if IsProject is false, it has to be checked. If gets unchecked, the IsProject value has to become 1.

Cristina
  • 55
  • 9

2 Answers2

1

I solved the issue so I'll post here the solution. As I didn't want to modify the model, I used another variable (somehow as David suggested) named NotShared and pass it to the ng-model and then as a parameter to the function from ng-change. I tried without passing it as a parameter but the value was not updating properly. Still don't know why.

<input type="checkbox"  ng-model="NotShared" name="IsProject" id="IsProject" ng-change="saveItem(list, 'IsProject', NotShared)"> Not Shared 
Cristina
  • 55
  • 9
0

I think you will have to use two different properties for this... So change this ng-model="list.IsProject" ng-checked="list.IsProject==false" to something like this

ng-model="list.IsProject" ng-checked="list.IsProject_2==false"

David Votrubec
  • 3,968
  • 3
  • 33
  • 44
  • Thank you for your response. I thought of this solution too, but this requires changes in the model and as the model is a bit complex I thought there could be a more simple way – Cristina Jul 07 '15 at 11:57