【发布时间】:2018-03-23 12:51:13
【问题描述】:
我在任何地方都找不到 Angular 中的放大弹出窗口 问题是 magnificPopup 无法被 jquery 识别
为了比较,我使用了 jquery-confirm,它可以工作。该过程与magnific popup相同,唯一不同的是调用方法为$.confirm({jquery-confirm stuff})
angular-cli.json
...
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/magnific-popup/dist/jquery.magnific-popup.min.js",
"../node_modules/bootstrap/dist/js/bootstrap.js",
...
package.json
...
"googleapis": "19.0.0",
"jquery": "3.2.1",
"jquery-confirm": "^3.3.2",
"magnific-popup": "^1.1.0",
"moment": "2.18.1",
...
Ts
import * as $ from "jquery";
...
setTimeout(()=>{
$(document).ready(function($){
alert();
$('.popupImage').magnificPopup({
type: 'image'
// other options
,
});
});
},2000)
【问题讨论】:
-
根据错误,似乎
jquery已加载,但magnific-popup未加载。 -
没有。停在这里。不要同时使用 Angular 和 jQuery。曾经。 jQuery 不知道 Angular 在 DOM 中生成了什么,Angular 也不知道 jQuery 在做什么。使用 Angular 或 jQuery,不要同时使用。
-
@JeremyThille - 我不同意(在这种情况下)。这个特殊的tool 是一个打开图像的 UI 工具,它依赖于 jquery。我看不出这有什么问题。如果问题是关于 DOM 或数据操作的,我会同意你的看法。
-
评论你的代码:不要使用
$(document).ready(,而是使用角度Lifecycle Hooks。 -
real world developing你以为我整天都在做什么?针织?好吧,好吧,继续加载两个不知道对方在做什么的库,祝你好运:)
标签: jquery angular magnific-popup