1

I think that i don't understand something.. Why I see "Undefined" in console?

  <script>
  function Controller($scope) {
   console.log($scope.name); 
  }  
  </script>

  <body ng-app ng-controller="Controller">
   <input type="text" value="3" ng-model="name">
  </body>

1 Answer 1

4

Angular does not process the value attribute. If you want to initialize the model value to something in the input, you need to use ng-init, f.ex.

<input ng-model="foo" ng-init="foo = 3">
Sign up to request clarification or add additional context in comments.

2 Comments

I seem to have a problem in which my containing controller of a form cannot access the ng-model stated inside the form's input tag. Why is this?
Hard to say without seeing your code etc., I'd suggest posting a new question and show the relevant pieces of code in it.

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.