2017-04-05 63 views
1

我是Angular JS的新手。我有以下<select>選項,我必須發送社區的id,即x.community_type_id以獲取子社區。如何使用AngularJS從選擇框中獲取ID

<select> 
    <option ng-repeat="x in myData" ng-click="sendID({{ x.community_type_id }})">{{ x.community_Type }}</option> 
</select> 

現在我正在使用以下代碼從Web服務中提取數據以選擇選項。

var app = angular.module('EntityApp', []); 
    app.controller('EntityAppCntroller', function($scope, $http) { 
    $http.get("http://111.222.22.333:1081/apartment/community/type/list") 
    .then(function (response) { 
     $scope.myData = response.data.type; 
    }); 

    $scope.sendID = function (id) { 
     alert(langKey); 
    } 
}); 

我想將x.community_type_id發送到Web服務。 這webservice的網址是這樣的:

http://11.338.41.149:8481/apartment/register/sub/community/type 

回答

0

刪除大括號中ng-click功能

<select> 
<option ng-repeat="x in myData" ng-click="sendID(x.community_type_id)">{{ x.community_Type }}</option> 
</select> 
0

試試這個 HTML

ng-click="sendID(x.community_type_id)" 

JS

$scope.sendID = function (id) { 
     $http({ 
      method:'GET', 
      url:'yoururl'+id, 
      data:{'id':id} 
      /// 
})   
    } 
2

在折角,當屬性與ng-開始,其被評估爲JavaScript的,因此你可以使用雙大括號做掉:

<select> 
    <option ng-repeat="x in myData" ng-click="sendID(x.community_type_id)">{{ x.community_Type }}</option> 
</select> 
0

嘗試這樣

<select ng-model="model" ng-options="x.community_type_id as  
    x.community_Type for x in myData" ng-click="sendID(model)"> 
<option ></option> 
</select> 
相關問題