angular.js - Angluar的点击事件,一般是用ng-click,还是在指令里面的link里面写?
迷茫
迷茫 2017-05-15 16:52:43
0
3
814

比如点击只做一些数据修改,一些dom的显示隐藏

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
習慣沉默

With ng-click, you can set a variable and use the value of the variable to control the area you want to show or hide through ng-show.

For example:

xxxxx
// 对controller里的值操作
ng-click="isShow=!isShow"

xxxxxx
// 改变后的值作用在视图上
ng-show="isShow"
迷茫

The DOM operation in the link can be a mouse stroke or a more complicated effect. For simplicity, I try to use ng-click and write a function in the scope to call it

为情所困

The poster’s answer is that for click events at any time, only ng-click is used. There is no usage scenario that needs to be written in the link in the instruction.

It’s also not clear what exactly the poster is asking about. The only click thing in Angular is ngClick. In many cases, it is wrong to use the traditional addEventListener in the link function. You should also use ngClick in the template of the instruction.

In fact, traditional DOM operations are only required for events that do not require drag and drop

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template