[英]How to catch click event on remote loaded data and displayed with angularJS
[英]How to catch event when click on link with the same url in AngularJS?
我有2個鏈接:
<a href="#link1">First</a>
<a href="#link2">Second</a>
和2個控制器:
app.controller('firstCtrl', function($scope) {
$scope.$on('$locationChangeStart', function (event, nextPage, currentPage) {
alert("ok");
}
app.controller('secondCtrl', function() {}
當我從第二個鏈接轉到第一個鏈接時,我看到警報。 如果我停留在第一個鏈接(= firstCtrl)並再次單擊第一個鏈接,如何添加事件?
注意:我要獲取新舊網址
如果您只是想在每次單擊第一個鏈接時觸發警報,則可能需要使用ng-click
屬性而不是$on('$locationChangeStart')
事件偵聽器,該事件偵聽器僅在URL路徑更改時才會觸發:
HTML
<div ng-controller="firstCtrl">
<a ng-click="link1()">First</a>
</div>
<div ng-controller="secondCtrl">
<a ng-click="link2()">Second</a>
</div>
JS
app.controller('firstCtrl', function($scope) {
$scope.link1 = function() {
alert("ok");
}
});
app.controller('secondCtrl', function() {...});
實際上,對於這種情況,最好更改按鈕的鏈接,以便用戶期望這些元素保留一些本地操作,而不是新頁面(部分)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.