Angular and mixing jQuery UI - Why not?

后端 未结 1 649
遥遥无期
遥遥无期 2020-12-03 15:33

I have the following code...

相关标签:
1条回答
  • 2020-12-03 16:31

    Using JQuery like this means that you are not declaratively expressing what your app does in the HTML which is kind of the point of Angular.

    From the angular homepage:

    AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop.

    Your also going to run into a lot of trouble down the road with code like

    $(document).ready(function() { $("#calendar").datepicker(); });
    

    As Angular has no idea when this has finished or what has changed. If you start using stuff like this you will need a strong understanding of how dirty checking and the digest cycle work in Angular.

    Your date picker won't play nice with other directives either. For example if you put this in an ng-if and hide and show it then the date picker will not be there anymore.

    Have you looked into libraries like Angular UI Bootstrap or Angular Strap. They both provide date pickers that work out of the box with Angular.

    0 讨论(0)
提交回复
热议问题