angularjs如何在按钮点击时绑定文本框值

时间:2017-11-07 03:24:32

标签: angularjs angular-ui-router

请帮助我如何在按钮点击事件

期间绑定这些ng-model(a,b)值
    <input type="text"  ng-model="a"/><b>Enter A Value</b>
    <input type="text" ng-model="b" /><b>Enter b Value</b>
    <button ng-click="Addition()">add</button>

Angular.js

$scope.Addition = function () {
        $scope.a = 10;
        $scope.b = 20;

        $state.go('Add', {
            a: $scope.a,
            b: $scope.b
        }
}

这里当我点击按钮a = 10 b = 20个值移动但不是我输入的

2 个答案:

答案 0 :(得分:2)

它的工作正常我没有看到任何问题

&#13;
&#13;
var app= angular.module("myApp",[])

app.controller("myController",function($scope){
$scope.Addition= function(){
console.log("Value of a is "+$scope.a);
console.log("Value of b is "+$scope.b);

}
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController">
 <input type="text"  ng-model="a"/><b>Enter A Value</b>
    <input type="text" ng-model="b" /><b>Enter b Value</b>
    <button ng-click="Addition()">add</button>
</div>
 
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这个 在HTML上

<input type="text"  ng-model="a"/><b>Enter A Value</b>
<input type="text" ng-model="b" /><b>Enter b Value</b>
<button ng-click="Addition(a,b)">add</button>

on js

$scope.Addition(a,b){
    console.log(a + " " + b)
}