我正在尝试调用一个函数,该函数通过链接从 servlet 返回一个 json 对象。
我的HTML链接,调用fTest函数:
<td><a href="" ng-controller="minaplantaCtrl" ng-click="fTest(x.id_camion_descarga)">ver</a></td>
我的 Controller :
app.controller('minaplantaCtrl', function($scope, $http, $window) {
$scope.fTest = function(idDescarga){
$http.get("http://localhost:8080/BD_INTEGRADA/UnionMinaPlanta?idDescarga="+idDescarga)
.success(function (response) {$scope.descargas = response.descargas;});
$window.alert(JSON.stringify($scope.descargas));
};
});
当我第一次按下时,链接在警报中显示为“未定义”
但是当我第二次按下时,如果我能看到在警报中返回的 json 对象
当我先点击链接时会发生什么?请帮忙
谢谢
最佳答案
这里的问题是你在成功回调之外警告 $scope.descargas 因此它确实没有定义但尝试像这样修改它。
app.controller('minaplantaCtrl', function($scope, $http, $window) {
$scope.fTest = function(idDescarga){
$http.get("http://localhost:8080/BD_INTEGRADA/UnionMinaPlanta?idDescarga="+idDescarga)
.success(function (response) {
$scope.descargas = response.descargas;
$window.alert(JSON.stringify($scope.descargas));
});
};
});
关于java - AngularJS 和 Servlet 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29809273/