如何使用 angularjs 将 html 输入值放入 ng-click 函数中
How to throw html input values into ng-click function with angularjs
大家好,我正在同时学习 html 和 angularjs time.I 不知道如何将简单的输入输入到我的函数中。
随机
<input id="input1" type="text">
<button ng-click="someAction()">click me</button>
基本上我想将输入中的文本值放入 someAction 方法中。抱歉,如果我的代码或问题令人困惑。我也很困惑。
我该怎么做?
angular.module('starter', [])
.controller('MainCtrl', function($scope) {
$scope.someAction = function(name) {
$scope.result = 'Hi ' + name;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
<div ng-app="starter" ng-controller="MainCtrl">
<!-- ngModel will store the input data, it's as if you were creating a variable -->
<input type="text" ng-model="name" placeholder="Your name"/>
<button ng-click="someAction(name)">Some action</button>
<p>{{result}}</p>
</div>
大家好,我正在同时学习 html 和 angularjs time.I 不知道如何将简单的输入输入到我的函数中。
随机
<input id="input1" type="text">
<button ng-click="someAction()">click me</button>
基本上我想将输入中的文本值放入 someAction 方法中。抱歉,如果我的代码或问题令人困惑。我也很困惑。
我该怎么做?
angular.module('starter', [])
.controller('MainCtrl', function($scope) {
$scope.someAction = function(name) {
$scope.result = 'Hi ' + name;
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.8.2/angular.min.js"></script>
<div ng-app="starter" ng-controller="MainCtrl">
<!-- ngModel will store the input data, it's as if you were creating a variable -->
<input type="text" ng-model="name" placeholder="Your name"/>
<button ng-click="someAction(name)">Some action</button>
<p>{{result}}</p>
</div>