How does data binding work in AngularJS?

前端 未结 14 1516
情话喂你
情话喂你 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:03

    AngularJs supports Two way data-binding.
    Means you can access data View -> Controller & Controller -> View

    For Ex.

    1)

    // If $scope have some value in Controller. 
    $scope.name = "Peter";
    
    // HTML
    
    {{ name }}

    O/P

    Peter
    

    You can bind data in ng-model Like:-
    2)

    
    
    
    {{ name }}

    Here in above example whatever input user will give, It will be visible in

    tag.

    If want to bind input from html to controller:-
    3)

    Here if you want to use input name in the controller then,

    $scope.name = {};
    
    $scope.registration = function() {
       console.log("You will get the name here ", $scope.name);
    };
    

    ng-model binds our view and render it in expression {{ }}.
    ng-model is the data which is shown to the user in the view and with which the user interacts.
    So it is easy to bind data in AngularJs.

提交回复
热议问题