Angular js. Pass data from form to model

Главная » 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.

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

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

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

Pin It on Pinterest

Share This