Can the ng-model value be altered without using the ng-change function? The method below does not seem to work.
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<input id="checkbox" type="checkbox" ng-model="field">
<div> {{field}} </div>
</div></div>
<script>
var myapp = angular.module('myApp', []);
myapp.controller('MyCtrl', function($scope){
if(document.getElementById("checkbox").checked){
$scope.field="YES";
}})
However, using the following code worked for me:
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<input id="checkbox" type="checkbox" ng-model="field" ng-change="change_text()">
<div>{{field}}</div>
<script>
var myapp = angular.module('myApp', []);
myapp.controller('MyCtrl', function($scope){
$scope.change_text = function() {
$scope.field="YES";
}})
</script>