user3096094 user3096094 - 2 months ago 10x
Javascript Question

AngularJS button submit not working

I am trying to call a Spring Restful service POST method from AngularJS.

Below is my JSP.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

<script type="text/javascript">
var app = angular.module("UserManagement", []);
app.controller("UserManagementController", function($scope, $http) {

//Initialize page with default data which is blank in this example
$scope.policy = [];
$scope.form = {
id : -1,
firstName : "",
lastName : "",
email : ""

//HTTP DELETE- delete employee by Id
$scope.submitEmployee = function(policy) {
method : 'POST',
url : '/Add_Policy',
data : angular.toJson($scope.form),
headers : {
'Content-Type' : 'application/json'
}).then(_success, _error);

} );
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>MMS Ensure</title>
<body ng-app="UserManagement"
<h1>New Policy</h1>
<!-- -->
<!-- -->
<from ng-submit="submitEmployee()">
Policy #:
<input type="text" ng-model="Policy">
<br> Policy Type:
<input type="text" ng-model="Type">
<br> Policy Tenture
<input type="text" ng-model="Tenture">
<br> Start Date:
<input type="text" ng-model="SDate">
<br> Holder Name:
<input type="text" ng-model="HName">
<br> Age:
<input type="text" name="Age">
<input type="submit">


If i press Submit button, its not calling my Service. Please help

More Info:
I am running this locally and in the same project Spring service also present. I tried to acess the $scope in browser console, it was throwing error saying its undefined.


You made typo, its form element not form

<from ng-submit="submitEmployee()">

should be

<form ng-submit="submitEmployee()">

Other thing is technically table can not have other element inside it directly expect tbody, tr, tfoot, thead, td, etc(they can be lie inside td/th). The current HTML which you had is wrong & invalid.

If you do inspect element you will find that the html which is there inside table must be thrown outside table element.

I don't see any reason you need table element here. You can simply remove table element wrapper.