jquery doens't work in angular 5

前端 未结 1 1944
长情又很酷
长情又很酷 2021-01-29 06:54

I\'m trying to use jquery in angular 5, specifically I\'m trying to use this library:

https://codepen.io/rstrahl/pen/eJZQej

These are the steps:

-->I cre

相关标签:
1条回答
  • 2021-01-29 07:21

    You should not use jQuery in Angular. While it is possible (how to do it you can see here How to use jQuery Plugin with Angular 4?), it is discouraged.

    Angular holds an own representation of the DOM in its memory and doesn't use query-selectors like jQuery. Instead all the DOM-manipulation is done by Renderer2 (and Angular-directives like *ngFor and *ngIf accessing that Renderer2 in the background/framework-code). If you manipulate DOM with jQuery yourself you will sooner or later run into synchronization problems and have things wrongly appearing or not disappearing at the right time from your screen, errors and simply not being able to test the application correctly (Jasmine requires you to know when elements have been rendered) or being able to use Angular Universal.

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