Can someone help me retrieve the value of an input field when a button is clicked?
Here is my controller code:
app.controller('MainCtrl', function($scope) {
$scope.test = function(val) {
alert(val);
}
});
This is my HTML snippet:
<body ng-controller="MainCtrl">
<input type="text" id="inputText">
<button type="button" ng-click="test(document.getElementById('inputText').value)">Test</button>
</body>
When I click the button, 'undefined' appears in the alert. Can anyone guide me on how to make this work in Angular?