我有一个下拉列表,在ng-change事件上,我需要将下拉列表值传递给$scope.getPIRData
函数,以便获得动态结果。
<div class="col-sm-4 col-lg-offset-4" ng-controller="myCtrl">
<select class="form-control" ng-model="sel_val" ng-change="getPIRData(sel_val)" ng-options="data.deveui for data in Customers"></select>
</div>
<script>
var app = angular.module('plunker', []);
app.controller('myCtrl', function ($scope, $http, $window) {
$scope.sel_val = 0;
$scope.DefaultLabel = "Loading.....";
var post = $http({
method: "get",
url: "../data.json",
dataType: 'json',
data: {},
headers: { "Content-Type": "application/json" }
});
post.success(function (data, status) {
$scope.Customers = data;
});
post.error(function (data, status) {
});
$scope.getPIRData = function (id) {
$http.get("/PIRDetails/GetPIRStatus/" + id)
.then(function (response) {
$scope.myWelcome = response.data;
console.log(JSON.stringify($scope.myWelcome));
});
};
});
</script>
答案 0 :(得分:1)
在ng-change指令中传递值。
ng-change="getPIRData(sel_val)"