Angular js. Pass data from form to model

Home » Tutorials » JavaScript » Angular js. Pass data from form to model
We will continue to build our angular app, Today we will realize adding data from form to model.
To make adding data to model from form with angular we need to do this steps:

  • adding angula directive ng-click to element which data will send to controller while click event. Value of this directive is method name. In our example it is addPlayer().
  • In controller we need to define method of the $scope object with the same name addPlayer. Also you need pass parameters to this method, namely form data. That’s why definition of the method will be addPlayer(playerName, playerTeam, playerCountry). Notice, parameters names match with ng-model directives in form input fields.
    As you know its purpose to bind data model with $scope object.


Submit a Comment

Your email address will not be published. Required fields are marked *

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This