ngclick deprecated. Popular alternative or solutio

2019-06-19 17:30发布

问题:

I'm new to angular. ng-click seems like a pretty core directive, I don't understand how you can make an app without ng-click. Am I missing something? Apparently it's deprecated. And the docs point me to fastclick but that's not an angular implementation.

Is there a popular non-deprecated way of doing what ng-click did? I couldn't find any popular packages on bower for this. Thanks.

回答1:

ng-click is only being deprecated within the ngTouch module due to delays when used in mobile browsers.

Beginning with Angular 1.5, this directive is deprecated and by default disabled. The directive will receive no further support and might be removed from future releases. If you need the directive, you can enable it with the $touchProvider#ngClickOverrideEnabled function. We also recommend that you migrate to FastClick. To learn more about the 300ms delay, this Telerik article gives a good overview.

Regular ngClick in the core ng module will remain unaffected.

If you do infact need to use fastclick as an alternative there are a couple of angular wrapped versions available. One, Two.