2016-08-01 5 views
1

EclipseでAngularJSとREST GET Webサービスを使用するWebアプリケーションを作成しました。 Webサービスを通じて、MySQLデータベースにデータを照会し、HTTP GETコントローラを介してHTMLページに値を送信します。 私のHTMLページにデータベースの値を含むドロップダウンリストを表示することに成功しました。今私はいくつかの新しいデータを生成する新しいクエリを作成できるように、各ドロップダウンリストの選択項目をjavaページに戻したいと思います。しかし、私はこの第二の部分をどうやってできるのか分からない、誰かがそれを手伝ってくれる?angularjs投稿Webサービスドロップダウン

ありがとうございます!

これは、両方の答えを

<div id="three" ng-controller="mycontroller"> 
      <table class="table table-hover"> 
       <tbody> 
        <select ng-model="selecteditem"> 
        <option ng-repeat="item in items"> 
         {{item.itemname}} 
         </option> 
         </select> 
       </tbody> 
      </table> 
        <b>You selected: {{selecteditem}}</b> 
      </div> 
<script> 
var app = angular.module('myApp', []); 
    app.controller('showitems', function($scope, $http) { 
      $http.get('http://localhost:8080/myproject/REST/WebService_items/GetItems'). 
      success(function(data) { 
       $scope.items = data; 
       }) 
       .error(function() { 
        $scope.items = "error in fetching data"; 

       }); 
     }); 
</script> 

答えて

0

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div id="three" ng-controller="mycontroller"> 
 
      <table class="table table-hover"> 
 
       <tbody> 
 
        <select ng-model="selecteditem"> 
 
        <option ng-repeat="item in items"> 
 
         {{item.itemname}} 
 
         </option ng-click="callTheFunction(item.itemname})"> 
 
         </select> 
 
       </tbody> 
 
      </table> 
 
        <b>You selected: {{selecteditem}}</b> 
 
      </div> 
 
<script> 
 
var app = angular.module('myApp', []); 
 
    app.controller('mycontroller', function($scope, customService) { 
 
    $scope.items = [{itemname:'apple'},{itemname:'mango'}] 
 
    $scope.callTheFunction=function(itemSelected){ 
 
     customService.restCallToJava(itemSelected) 
 
    } 
 
    app.service('customService',['$http', function($http) { 
 
     var restCallToJava= function(sensorObj){ 
 
     return $http.post('/api',sensorObj); 
 
     } 
 
    }]) 
 
    
 
</script>

0
<label>example</label> 
    <md-select id="example" ng-model="vm.list.example" required> 
    <md-option ng-repeat="unit in vm.list" value="{{example.id}}">{{example.name}}</md-option> 
+0

このコードは質問に答えるかもしれませんが、問題の解決方法および/または理由を説明する追加のコンテキストを提供すると、回答の長期的価値が向上します。 – HiDeo

0

おかげで私のhtmlページの一部です!私の主な問題は、ドロップダウンリストに項目を表示する方法ではなく、私はそれをやりました。選択したアイテムをREST Webサービス機能を使用してプロジェクトのJavaページに送信したいので、WebサービスのURLに項目をプッシュ/ポストして送信するHTMLページにangularjsコードを記述する方法がわかりません。