gpt4 book ai didi

jquery - 我们可以在 Web 应用程序中同时使用 jQuery 和 AngularJS 吗?

转载 作者:行者123 更新时间:2023-12-03 22:40:05 25 4
gpt4 key购买 nike

我们可以在 Web 应用程序中同时使用 jQuery 和 AngularJS 吗?我读过一些建议,建议不要在项目中同时使用两者,因为两者都有不同的生命周期。

我们的要求是使用 ASP.NET WebApi 和 AngularJS 构建响应式 Web 应用程序;现在,为了使我们的应用程序具有响应能力,我们希望使用 Bootstrap,而 Bootstrap 需要 Bootstrap CSS 和 jQuery 库;那么我们应该将 jQuery 库和 AngularJS 库都添加到我们的项目中吗?

最佳答案

是的,您可以,但不建议这样做,因为 jQuery 会增加很多开销。如果您以“Angular 方式”进行编码,那么您将不会破坏 Angular 功能。例如,如果您尝试调整字段的值,那么您的范围将不会更新,直到您手动触发摘要。它会导致垃圾代码和不一致的行为。

Does Angular use the jQuery library?

Yes, Angular can use jQuery if it's present in your app when the application is being bootstrapped. If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.

Angular 1.3 only supports jQuery 2.1 or above. jQuery 1.7 and newer might work correctly with Angular but we don't guarantee that.

Source

另请参阅此问题:Should we use jQuery with AngularJS?

如果您确实确定要使用 jQuery,请确保首先包含 jQuery 脚本。然后 Angular 将加载 jQuery 来代替 JQ lite。

关于jquery - 我们可以在 Web 应用程序中同时使用 jQuery 和 AngularJS 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39699238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com