我试图通过点击提交按钮来调用控制器中存在的功能
<div ng-app="" ng-controller="studentController">
<table>
<tr>
<th>Name</th>
<th>Roll No</th>
<th>Percentage</th>
</tr>
<tr ng-repeat="student in students">
<td>{{ student.Name }}</td>
<td>{{ student.RollNo }}</td>
<td>{{ student.Percentage }}</td>
</tr>
</table>
<input type="text" ng-model=firstName /> <input type="text"
ng-model=lastName /> <input type="number" ng-model=salary /> <input
type="submit" onsubmit="saveEmployee()">
</div>
<script>
function studentController($scope, $http) {
$scope.saveEmployee = function() {
$http({
url : "studentData",
method : "POST",
params : {
firstName : "Sparsh",
lastName : "Khandelwal",
salary : 200000
}
}).success(function(response) {
$scope.students = response;
});
}
}
</script>
我认为它会发送服务器端请求,而不是它没有调用函数
答案 0 :(得分:4)
所以,onsubmit
不是Angular绑定。它将尝试在您的Javascript全局范围内引用saveEmployee()
函数。您将要使用ngSubmit
来引用Angular Controller范围内的功能:
ngSubmit :启用将角度表达式绑定到onsubmit事件。