Angularjs 单个控制器中的多个get请求
我有一个应用程序模块和应用程序控制器。当我尝试使用一个get请求时,结果会显示出来,但当我尝试再执行一个get请求时,我想可能存在问题Angularjs 单个控制器中的多个get请求,angularjs,Angularjs,我有一个应用程序模块和应用程序控制器。当我尝试使用一个get请求时,结果会显示出来,但当我尝试再执行一个get请求时,我想可能存在问题 var app = angular.module('bizapp', []); app.controller('landcont', function($location, $scope, $http, $window){ $scope.user = $location.search().username; **//This one works. res
var app = angular.module('bizapp', []);
app.controller('landcont', function($location, $scope, $http, $window){
$scope.user = $location.search().username;
**//This one works. result comes.**
$http({
method : "GET",
url : "webapi/company/apps"
}).then(function mySucces(response) {
$scope.records= response.data;
}, function myError(response) {
$scope.apps= response.statusText;
});
$scope.redir=function(event){
**//This one doesnot work. no result comes.**
$http({
method : "GET",
url : "webapi/login/usermap"
}).then(function mySuccesss(res) {
alert(res);
}
var uri= 'http://localhost:8080/bizlms/bizint.php?app='+event.target.id;//+encodeURIComponent(query);
$window.open(uri, "_self");
}`
有人能帮忙吗 您的第一个
$http
调用在定义控制器时运行。第二个在函数中。仅在$scope上定义函数redir
,并不意味着它已被执行。在模板中,您可以使用
<span ng-click="redir()">click me</span>
点击我
在第二个$http
promise的函数调用中添加一个结束)
括号:
$http({
method : "GET",
url : "webapi/login/usermap"
})
.then(function(res) {
alert(res);
}); // <----------- Add closing ")" here
$http({
方法:“获取”,
url:“webapi/login/usermap”
})
.然后(功能(res){
警报(res);
}); // 第二个$http
调用位于名为$scope.redir
的函数中,如果您不运行该函数,它将不会运行您的$http
请求!我知道@MatthewCawley…我实际上是在点击事件中调用此函数…第二个http不起作用…好的,对不起,我不想忽略“明显的”。您似乎还缺少第二个$http
promise的然后函数调用的结束()
括号。实际上,我在单击事件时调用$scope.redir。函数正在执行..比如..$scope.redir=function(event){alert(“hi”)}
可以工作…但是正如您在代码中看到的,我已经通知了第二个HTTP调用的结果…这就是我遇到的问题。是否存在类似于多个HTTP调用在一个控制器上不工作之类的情况?可能HTTP请求失败。尝试向/console.log()发出错误警报,并查看开发人员工具中的“网络”选项卡