在我的应用程序中,我想在发生ng-click事件时触发ajax调用:
<ul class="sub">
<li>
<a href="javascript:;" ng-class="{active : isSet(1)}" ng-click="getData(); setTab(1)">Bla bla bla</a>
</li>
</ul>
我的剧本:
angular.module('mainApp', ['smart-table'])
.controller('TabController', ['$scope', function ($scope, $http)
{
$scope.tab = 2;
$scope.setTab = function (newTab)
{
$scope.tab = newTab;
};
$scope.isSet = function (tabNum)
{
return $scope.tab === tabNum;
};
$scope.getData = function ()
{
$http({
url: "/goodsList",
method: "GET"
}).success(function (data, status, headers, config)
{
angular.copy(data, $scope.oriList);
}).error(function(data, status, headers, config)
{
alert('Error getting data');
});
};
}]);
当我在IntelliJ上调试我的脚本时,它在登录部分停止,响应是userinfo(这是spring sercurity服务的响应)。除了li标签之外,没有任何代码可以触发ajax调用。
答案 0 :(得分:0)
<强> 修改 强>
JS
angular.module('mainApp', [])
.controller('TabController', ['$scope','$http' ,function ($scope, $http)
{
$scope.tab = 2;
$scope.setTab = function (newTab)
{
$scope.tab = newTab;
};
$scope.isSet = function (tabNum)
{
return $scope.tab === tabNum;
};
$scope.getData = function(){
$http({
url: "/goodsList",
method: "GET"
}).then(function(response){
angular.copy(data, $scope.oriList);
} , function(response){
alert('Error getting data');
});
}
$scope.s = function(){
alert("AXX");
}
}]);
HTML
<div ng-app="mainApp" >
<div ng-controller="TabController">
<ul class="sub">
<li>
<button ng-class="{active : isSet(1)}" ng-click="getData(); setTab(1)">Bla bla bla</button>
<button ng-click="s()">
omri lugasi
</button>
</li>
</ul>
</div>
</div>
答案 1 :(得分:0)