ionic 2和strophe不工作?

时间:2022-09-05 18:53:04

I am currently trying to use strophe with ionic 2, I have npm both strophe and jquery and also @types/strophe and typings.

我现在正在尝试用ionic 2来使用strophe,我有npm两个strophe和jquery,还有@types/strophe和typings。

this is my code

这是我的代码

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {Strophe} from 'strophe';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {


  public connection: any ;

  public BOSH_SERVICE: any="http://52.32.***.5:5280/http-bind/" ;


constructor(public navCtrl: NavController) {

}


login() {


  this.connection = new Strophe.Connection(this.BOSH_SERVICE);
  this.connection.connect('ama****'+'@'+'localhost', 'o***oop', this.onConnect);

  console.log("Hello World !");

 }



onConnect(status) {
  console.log('onConnect: '+status);
}

when I try ionic serve I get this error

当我尝试离子发球时,我得到了这个错误

TypeError: __WEBPACK_IMPORTED_MODULE_2_strophe__.Strophe is undefined
Stack trace:
HomePage.prototype.login@http://localhost:8100/build/main.js:55747:9
View_HomePage_0/<@ng:///AppModule/HomePage.ngfactory.js:135:21
viewDef/handleEvent@http://localhost:8100/build/main.js:12170:98
callWithDebugContext@http://localhost:8100/build/main.js:13462:39
debugHandleEvent@http://localhost:8100/build/main.js:13050:12
dispatchEvent@http://localhost:8100/build/main.js:9070:12
renderEventHandlerClosure/<@http://localhost:8100/build/main.js:9662:20
decoratePreventDefault/<@http://localhost:8100/build/main.js:33505:53
f</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9644
                                                                                                                                                                 NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<.onInvokeTask@htt           p://localhost:8100/build/main.js:4397:28
f</t.prototype.invokeTask@http://localhost:8100/build/polyfills.js:3:9557
c</r.prototype.runTask@http://localhost:8100/build/polyfills.js:3:4812
t/this.invoke@http://localhost:8100/build/polyfills.js:3:10626

1 个解决方案

#1


2  

1) download Strophe library from Strophe Site

1)从Strophe站点下载Strophe库。

Then, You should put the framework inside /src/assets/

然后,您应该将框架放在/src/assets/中

Then, You should add the script tag to the index.html before polyfills.js and main.js

然后,您应该将脚本标记添加到索引中。html polyfills之前。js和main.js

Thus

因此

<script src="assets/strophejs-1.2.14/strophe.js"></script>

Last,

最后,

you should put this declare statement before to use the strophe.

您应该在使用strophe之前放置声明语句。

declare var Strophe: any;

It works for me!

跟我想的一样!

2) another way is you can install using

2)另一种方式是你可以使用

npm install strophe.js

and copy strophe.js file from node_modules/strophe.js folder to your src/assets folder as above and then give path in your index file

诗节和副本。js文件从node_modules /诗节。将js文件夹放到src/assets文件夹中,然后在索引文件中提供路径。

#1


2  

1) download Strophe library from Strophe Site

1)从Strophe站点下载Strophe库。

Then, You should put the framework inside /src/assets/

然后,您应该将框架放在/src/assets/中

Then, You should add the script tag to the index.html before polyfills.js and main.js

然后,您应该将脚本标记添加到索引中。html polyfills之前。js和main.js

Thus

因此

<script src="assets/strophejs-1.2.14/strophe.js"></script>

Last,

最后,

you should put this declare statement before to use the strophe.

您应该在使用strophe之前放置声明语句。

declare var Strophe: any;

It works for me!

跟我想的一样!

2) another way is you can install using

2)另一种方式是你可以使用

npm install strophe.js

and copy strophe.js file from node_modules/strophe.js folder to your src/assets folder as above and then give path in your index file

诗节和副本。js文件从node_modules /诗节。将js文件夹放到src/assets文件夹中,然后在索引文件中提供路径。

相关文章