0
我刚在一个角函数里面使用了一个jquery,并试图通过ng-click来调用。它可以正常工作,但我总是需要按钮第二次点击调用该函数jquery里面的角函数需要双击才能调用
这是我的函数调用语句
<button type="button" class="btn btn-primary showRest" id="btnShow" ng-click="loadHotels()">Show Restaurants</button>
这是我的角度函数调用一个服务,如果成功,它滚动到一个div
$scope.loadHotels = function() {
$scope.setPlace();
if (p != null) {
$http({
method: 'POST',
url: 'http://localhost/fudline/access/hotels/loadhotelsfromplace',
data: $httpParamSerializerJQLike({
place: p
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.success(function(data, status, headers, config) {
$scope.hotels = data;
$(".showRest").click(function() {
$('html,body').animate({
scrollTop: $(".hotels").offset().top
},
'slow');
});
}).error(function(data, status, headers, config) {
//
});
}
}
<button type="button" class="btn btn-primary showRest" id="btnShow" ng-click="loadHotels()">Show Restaurants</button>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
它是去...
节<div class="container text-center hotels">
<h3>Trending Restaurants</h3>
</div>
为什么你需要再次点击相同元素的成功? – sTx
您不需要事件处理程序在成功回调时调用方法。只要删除事件处理程序 – CrazyMac