How does data binding work in AngularJS?

前端 未结 14 1546
情话喂你
情话喂你 2020-11-21 05:41

How does data binding work in the AngularJS framework?

I haven\'t found technical details on their site. It\'s more or less clear how it works when data

14条回答
  •  攒了一身酷
    2020-11-21 06:11

    Here is an example of data binding with AngularJS, using an input field. I will explain later

    HTML Code

    {{watchInput}}

    AngularJS Code

    myApp = angular.module ("myApp", []);
    myApp.controller("myCtrl", ["$scope", function($scope){
      //Your Controller code goes here
    }]);
    

    As you can see in the example above, AngularJS uses ng-model to listen and watch what happens on HTML elements, especially on input fields. When something happens, do something. In our case, ng-model is bind to our view, using the mustache notation {{}}. Whatever is typed inside the input field is displayed on the screen instantly. And that's the beauty of data binding, using AngularJS in its simplest form.

    Hope this helps.

    See a working example here on Codepen

提交回复
热议问题