如何将值从文本框传递给AngularJs中的函数?

Vis*_*uli 3 angularjs

我的HTML:

<input type ="text" ng-model="contactid" >
Run Code Online (Sandbox Code Playgroud)

我想将此框中输入的contactId值传递给在框abc()后面调用onclick提交按钮的函数.

我该怎么做呢?

pgr*_*ues 8

你可以这样做:

<form ng-controller="formCtrl">     
    <input type="text" name="name" ng-model="inputValue" />
    <button ng-click="abc(inputValue)"></button>
</form>
Run Code Online (Sandbox Code Playgroud)

或者使用ng-submit指令:

<form ng-controller="formCtrl" ng-submit="abc(inputValue)">     
    <input type="text" name="name" ng-model="inputValue" />
    <button type="submit"></button>
</form>
Run Code Online (Sandbox Code Playgroud)

在你的formCtrl控制器中:

.controller('formCtrl', function () {
    $scope.inputValue = null;
    $scope.abc = function (value) {
        console.log(value);
    };
});
Run Code Online (Sandbox Code Playgroud)