Issue on prepopulating model value on view init in angularJS -
i want prepopulate input field controller:
here input field:
<input class="form-control" type="text" name="partnername" placeholder="completeaza numele partenerului" ng-model="partnernamemodel.field" required validate-field="partnernamemodel">
in controller, if this:
partnernamemodel.field = 'test';
i next error:
typeerror: cannot set property 'field' of undefined
so, had this:
$scope.partnernamemodel = {field: 'dsad'};
i practice?
is there improve way prepopulate fields?
you can create object partnernamemodel doing
$scope.partnernamemodel = {}
at top of controller can utilize dot syntax set values like
$scope.partnernamemodel.value = "foo" $scope.partnernamemodel.bar = "lemons"
this how work objects in angular
angularjs
No comments:
Post a Comment