如何在 ionic 3 中使用 jquery [英] How to use jquery in ionic 3

查看:27
本文介绍了如何在 ionic 3 中使用 jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ionic 3 中的 jquery 在 div 中加载外部网站.

I'm trying to load external website in a div using jquery in ionic 3.

TS:

export class HomePage 
{
  constructor(public navCtrl: NavController) {    
      $('#loadExternalURL').load('http://www.google.com');
  }
}

HTML:

<ion-content>
    <div id="loadExternalURL"></div>
</ion-content>

我在为 ionic 应用程序提供服务时出现黑屏.有什么我想念的吗?有什么建议吗?

I'm getting blank screen on serving the ionic app. Is there anything I'm missing? Any Suggestion?

推荐答案

我是按照下面的方法做的,

I did it in following way,

  1. 在您的 IONIC-3 应用中安装 Jquery 模块,

  1. Install Jquery module in your IONIC-3 app,

npm install jquery --save

在 HomePage.ts 中导入 JQuery

Import JQuery in HomePage.ts

从 "jquery" 导入 * 作为 $;

使用$调用jquery方法.

Use $ to call jquery methods.

我等待方法 ngAfterViewInit 以确保视图已初始化.

I wait for method ngAfterViewInit to make sure view is initialized.

ngAfterViewInit(){
    $(document).ready(function(){
        alert('JQuery is working!!');
    });
}

这篇关于如何在 ionic 3 中使用 jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆