search

Home  >  Q&A  >  body text

angular.js - How to implement data binding after click event in angular?

After clicking the OK button, the edited data will be displayed on the page. How to implement this using angular
`your name: <input type="text" ng-model="yourname"/>
<button>OK</button>
Hello {{yourname}}!`

PHP中文网PHP中文网2792 days ago648

reply all(2)I'll reply

  • 黄舟

    黄舟2017-05-15 16:57:04

    Then your code should look like this:

    var model = angular.module('demo', []);
    
    model.controller('DemoCtrl', function($scope){
        $scope.user = {};
        $scope.username = '';
        
        $scope.confirm = function(){
            $scope.user.username = $scope.username;
            $scope.username = '';
        };
    });
    your name: <input type="text" ng-model="username"/>
    <button ng-click="confirm()">确定</button>
    Hello {{ user.username }}!

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-15 16:57:04

    You can change ng-model to name
    hello{{confirmNmae}}
    Achieve value assignment in the controller

    reply
    0
  • Cancelreply