簡體   English   中英

使用html5數據操作和角度

[英]using html5 data-action and angular

在開始使用angularjs之前,我正在使用jquery ealier。

之前我提到過:

$('[data-action^="backtop"]').click(function(){

});

現在,在集成角度后,單擊時不起作用。

有沒有一種方法可以糾正而不必將所有內容更改為指令。

您要在其中放置data-action ,然后在其上方觸發處理程序的選擇器的位置-使用ng-click

在模板中:

<div ng-controller="MyCtrl as ctrl"> <!-- or whatever container --> 
 <button ng-click="ctrl.backtop()" ng-init="count=0">
</div>

並在控制器中:

class MyCtrl {
    backtop() {
       // code here, what you had in the click handler
    }
}
app.controller("MyCtrl", MyCtrl);

或使用ES5語法:

app.controller("MyCtrl", function(){ 
    this.backtop = function() { /* handler code here */ }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM