search

Home  >  Q&A  >  body text

angular.js - 在Angular开发中,为什么要选用ng-click而不用原生的click

刚刚接触Angular,希望大神指点。

淡淡烟草味淡淡烟草味2744 days ago542

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-05-15 16:55:48

    1. Because of ng-click中解析的是AngularJs表达式,而原生的click只是单纯的运行JavaScript’s code.
    2. For expressions about AngularJS, you can see here (need to circumvent the wall), or here (no need to circumvent the wall).
    3.ng-clickCoupled with other commands, it can show its powerful capabilities.
    4. Another problem is the scope of ng-click它的作用域在声明它的那个控制器的作用域内,而原生click. Its scope is within the scope of the controller where it is declared, while the scope of native click is generally global.
    5. I have written here a commonly used example portal, I hope it can be of some help to you. ng-click

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 16:55:48

    ng-click is a directive of angular, and the attribute value is an expression. It is an optimization of onclick. The functions it can achieve can also be achieved by onclick, but ng-click is more intelligent. For example, angular has already packaged it for you. The scope corresponding to ng-click, etc. But the scope of onclick needs to be set by yourself
    For specific differences, please see the difference between ng-click and onclick here

    I think it’s similar to the difference between jquery and native javascript

    reply
    0
  • Cancelreply