Reputation: 39374
I have the following Angular code
controller:
app.controller('MainCtrl', function($scope) {
var vm = this;
vm.job = null;
vm.create = function (job) {
vm.job = job;
}
});
HTML:
<div ng-controller="MainCtrl as vm">
<span data-ng-bind="vm.job.position"></span>
<form name="form" data-ng-submit="vm.create(vm.job)">
<label for="position">Position</label>
<input id="position" name="vm.job.position" type="text" data-ng-model="vm.job.position" />
<button>Create</button>
</form>
</div>
But when I submit the form I don't see the Position value.
Any idea why?
Upvotes: 0
Views: 285
Reputation: 691725
Because
controller as
.Note that you don't even need to submit, since the job you're binding is already vm.job
. Your create(vm.job)
method call does nothing: it assigns vm.job
to vm.job
.
Upvotes: 6