首頁  >  問答  >  主體

angular.js - angular 怎麼實作點擊事件之後再進行資料綁定?

點擊確定按鈕之後,再將編輯的資料展示在頁面上,用angular該怎麼實現
`your name:

Hello {{yourname}}!`

PHP中文网PHP中文网2714 天前595

全部回覆(2)我來回復

  • 黄舟

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

    那你的程式碼應該是這個樣子嘍:

    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 }}!

    回覆
    0
  • 天蓬老师

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

    可以將ng-model改為name
    hello{{confirmNmae}}
    在controller中實現賦值

    回覆
    0
  • 取消回覆