0

i am having play around with angular and i am trying to store a name entry to a variable. When you type your name in and click next i want to take the data from the input field and store that into a variable. Can this be done and if so whats the best way to go about this? iv provided a non working example below

HTML:

 <button class="button" ng-click="next()"> Next</button>
     <form>
      <label class="item">
       <input ng-model="name" type="text" placeholder="Enter your name"></input>
      </label>
     </form>
    <h3 style="color:black">{{name}}</h3>

JS:

  $scope.next = function() {
    var nameresult = $scope.name;
  };
1
  • 1
    Yes you can do it..and your code should work? nameresult will be local to the next function Commented Jan 8, 2015 at 20:34

1 Answer 1

1

When you're binding, you are actively writing to a variable in the model of the controller. If you want it to be a specific object you can define it on the scope ($scope.myObject) and bind to that (ng-model="myObject.Value").

See this plunker for example: plink plunk

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.