search

Home  >  Q&A  >  body text

angular.js - 关于jquery与agularjs的问题

本人最近在学习agularjs, 发现如果说是对于dom操作angular 并没有jquery来的好用,所以希望将两者结合使用,但是有人就对我说不建议这么做,问一下,将两者结合使用有什么弊端吗?是维护困难,还是两者会产生冲突?

巴扎黑巴扎黑2744 days ago571

reply all(2)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-15 16:57:45

    First of all, when using angular 和用 jquery for implementation, their ideas are completely different.

    angular 要求我们不要有 先设计页面,然后用DOM来展现它而是总是以架构的思维去思考的基础。
    jquery 是在拓展和增强dom 的基础上壮大的,它仅仅只是一个库一个以dom 为基础的库(当然,它也有很多其它不以dom为基础的的功能ajax,utility等)
    其次 angular 的数据绑定特性使的在用jquery 来操作dom becomes redundant.
    Back to the question:

    • What are the disadvantages of combining the two?

    Answer: It’s not necessary and not worth it. Most js plug-ins and extensions can actually be rewritten with very little js. And it will make the code less and more concise.

    As for conflict, they can actually be used together very well.

    There is a little difference regarding maintenance. Ease of maintenance depends on design and specifications. Just compare angular and jquery. Angular is easier to maintain. The reason is determined by the characteristics of angular.

    Refer to StackOverFlow’s wonderful Q&A appreciation

    Above

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 16:57:45

    Angular操作DOM是有那么一点麻烦,不过当你用熟了它的那一套东西之后,就会发觉其实Angular操作DOM也是不错的。
    之所以不建议两者结合起来使用,很大程度是因为使用了jQuery后,测试维护都变得很困难;而Angular是测试驱动的,所以不建议这样做。
    如果在刚开始觉得使用Angular的那一套很不方便的话,是可以使用jQuery的;官方也有关于使用jQueryInstructions, details can be found here Does Angular use the jQuery library?.

    reply
    0
  • Cancelreply