2016-08-13 10 views
1

AngularJSからSpring RestfulサービスのPOSTメソッドを呼び出そうとしています。AngularJSボタンが機能しません。

以下は私のJSPです。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<script 
    src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script> 

<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) { 
        $http({ 
         method : 'POST', 
         url : '/Add_Policy', 
         data : angular.toJson($scope.form), 
         headers : { 
          'Content-Type' : 'application/json' 
         } 
        }).then(_success, _error); 
       }; 


      }); 
</script> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>MMS Ensure</title> 
</head> 
<body ng-app="UserManagement" 
    ng-controller="UserManagementController"> 
    <h1>New Policy</h1> 
    <!-- https://dzone.com/articles/building-rest-service-collects --> 
    <!-- http://howtodoinjava.com/angularjs/angularjs-http-restful-api-example/ --> 
    <from ng-submit="submitEmployee()"> 
    <table> 
     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"> 
     <br> 
     <input type="submit"> 
    </table> 
    </from> 

</body> 
</html> 

私が[送信]ボタンを押すと、そのサービスが呼び出されません。助けてください

詳細情報: 私はこれをローカルで、同じプロジェクトで実行しています。春のサービスもあります。私はブラウザのコンソールで$スコープにアクセスしようとしましたが、それは未定義と言ってエラーを投げていました。あなたがタイプミスをした

+0

フォームタグに入力ミスがあります。 – d4vsanchez

+0

からフォームにする必要があります。ありがとうございます! – Geek

答えて

0

、そのform要素ではないfrom

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

は、それが直接tbodytrtfoottheadを期待して内部の

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

他の事は技術的にtableは、他の要素を持つことができないされなければなりません、tdなど(これらは内部にあることができますtd/th )。あなたが持っていた現在のHTMLは間違っています&が無効です。

あなたは要素を調べ行う場合は、tableの内側にありhtmltable要素をスローしなければならないことがわかります。

ここにtable要素が必要な理由はありません。要素ラッパーtableを単純に削除できます。タイプミスがあります

0

、それは

<form ng-submit="submitEmployee()"> 
<table> 
    <thead> 
     <tr> 
      <td> 
      </td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr> 
      <td> 
      </td> 
     </tr> 
    </tbody> 
    <tfoot> 
     <tr> 
      <td> 
      </td> 
     </tr> 
    </tfoot> 
</table> 

すべきであり、それは別々のファイルにあなたのコントローラとhtmlを保つために良いpraticeです。

+0

この回答で提供された新しい情報はありません。 –

関連する問題