该块显示数据库中的值。选择值后,我要提取ID。
<div class="block">
<label>Refer</label>
<select ng-controller="selectRefer">
<option ng-repeat="ref in refer">{{ref.refer}}</option>
</select>
<button ng-click="MyFunction()"> - </button> //тут я бы хотел
через ng-click изьять
//данные из тега select и передать в
//контроллер и
</div>
控制器
selectInfo.controller('selectRefer', ['$scope', '$http',
function ( $scope, $http) {
$http({
method: 'get',
url: 'mysite',
}).then(function successCallback(response) {
// Store response data
$scope.refer = response.data;
$scope.id = response.id
});
}]);
如何通过单击按钮从选项标签中获取ID-我不明白。
答案 0 :(得分:1)
您应该使用ng-options而不是ng-repeat
<select ng-controller="selectRefer"
ng-options="ref.id as ref.name for ref in refer track by ref.id"
ng-model="selectedRef">
<option value="">Select</option>
</select>
<button ng-click="MyFunction(selectedRef)"> - </button>
$scope.MyFunction= function(selectedRef){
console.log(selectedRef);
}