我有一个 Web 服务,它在调用时返回 json 文件,并带有条目 id 的参数。我有一个 Angular 方法,它返回从该方法返回的数据。我不知道如何在 id 的输入发生更改时调用该服务,因为我想在提供新值时调用该方法。
我为 Id 传入的参数称为 Reference。 HTML 返回引用为 1234 的对象,但如果我更改该值,我不知道如何调用该服务。
这是我到目前为止所拥有的:
Angular :
var app = angular.module("myModule", [])
.controller("myController", function ($scope, $http) {
var res = $http({
method: 'GET',
url: 'AirPortrWebService.asmx/DashboardDetail',
params: { Reference : '1234' }
})
.then(function (response) {
$scope.booking = response.data
});
$scope.test = "Angular Method Called";
$scope.Reference = '1234';
});
HTML
<!DOCTYPE html>
<html>
<head>
<script src="scripts/angular.js"></script>
<script src="app/NewAppTwo.js"></script>
</head>
<body ng-app="myModule" ng-controller="myController">
{{test}}
{{Reference}}
<br />
<br />
<input type="text" ng-model="Reference" ng-change="booking"/>
{{booking}}
</body>
</html>
最佳答案
将 ng-change="booking"更改为每次模型引用更改时调用的函数:
$scope.getReference = function(referenceNumber){
$http({
method: 'GET',
url: 'AirPortrWebService.asmx/DashboardDetail',
params: { Reference : referenceNumber}
}).function (response) {
$scope.booking = response.data
});
}
<input type="text" ng-model="Reference" ng-change="getReference(Reference)"/>
关于javascript - AngularJS:在文本框中的值更改时调用 httpget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34661824/