HTML:
...
<input ng-init="item.check=false" type="checkbox" ng-model="item.check">
...
<input ng-init="item.name=''" class="form-control" ng-model="item.name">
...
JS:
var myApp = angular.module('myApp', []);
myApp.controller('AppCtrl', function ($scope, $http) {
var refresh = function() {
$scope.item.check = false;
$scope.item.name = "";
}
//Call upon loading app to initialize values, also called upon events to refresh the field
refresh();
I initially thought that just the JS is sufficient to initialize the values and so I got rid of both the checkbox and the form's ng-init then ended up getting the error:
TypeError: Cannot set property 'name' of undefined
The app works if I just leave both ng-init. It also works when I remove the ng-init from only one of the 2 elements (so either from the checkbox or the form) but it will not work if I remove both. What is going on here? Am I doing this correctly or is there a better way to initialize?
Thanks.