0

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?

1 Answer 1

6

Because

  1. You forgot to add ng-app to the body or html element
  2. You're using angular 1.0.8, which is completely obsolete, and doesn't support 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.