Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 离子2与strophe不工作?_Javascript_Jquery_Node.js_Angular_Ionic2 - Fatal编程技术网

Javascript 离子2与strophe不工作?

Javascript 离子2与strophe不工作?,javascript,jquery,node.js,angular,ionic2,Javascript,Jquery,Node.js,Angular,Ionic2,我目前正在尝试将strophe与ionic 2一起使用,我有npmstrophe和jquery,还有@types/strophe和打字 这是我的密码 import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import {Strophe} from 'strophe'; @Component({ selector: 'page-home', templateUr

我目前正在尝试将strophe与ionic 2一起使用,我有npm
strophe
jquery
,还有
@types/strophe
和打字

这是我的密码

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);
}
当我尝试离子发球时,我得到了这个错误

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
TypeError:\u网页包\u导入的模块\u 2\u strophe\u。strophe未定义
堆栈跟踪:
主页.原型。login@http://localhost:8100/build/main.js:55747:9
查看主页(0/1)从Strophe下载Strophe库

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

然后,应该在polyfills.js和main.js之前将脚本标记添加到index.html

因此

这对我有用

2) 另一种方法是您可以使用

npm install strophe.js

并将strophe.js文件从node_modules/strophe.js文件夹复制到您的src/assets文件夹,如上所述,然后在索引文件中给出路径

我认为您需要安装另一个文件。PM strophe在节点模块中包括strophe.js。它的新版本1.2.4未折旧,但专为npm和node设计。啊,好的。。我的错。。当我从npmI检查它时,它在命令行中提到了弃用,我不知道可能是你的权利,但它是npm中唯一的名称空间。看起来名称空间是从“Strophe”定义的try
import*作为Strophe
declare var Strophe: any;
npm install strophe.js