2017-05-29 75 views
2

我目前正試圖使用​​strophe與離子2,我有npm strophejquery@types/strophe和typings。離子2與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: 
[email protected]://localhost:8100/build/main.js:55747:9 
View_HomePage_0/<@ng:///AppModule/HomePage.ngfactory.js:135:21 
viewDef/[email protected]://localhost:8100/build/main.js:12170:98 
[email protected]://localhost:8100/build/main.js:13462:39 
[email protected]://localhost:8100/build/main.js:13050:12 
[email protected]://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</[email protected]://localhost:8100/build/polyfills.js:3:9644 
                                           NgZone.prototype.forkInnerZoneWithAngularBehavior/this.inner<[email protected]   p://localhost:8100/build/main.js:4397:28 
f</[email protected]://localhost:8100/build/polyfills.js:3:9557 
c</[email protected]://localhost:8100/build/polyfills.js:3:4812 
t/[email protected]://localhost:8100/build/polyfills.js:3:10626 
+0

我認爲你需要安裝[strophe.js](https://www.npmjs.com/package/strophe.js)另一個似乎不贊成 –

+0

Npm strophe在節點模塊中包含strophe.js它的新版本1.2 .4不折舊,但專門用於npm和節點。 –

+0

啊好的..我的壞..它在命令行中提到棄用時,我從npm –

回答

2

1)的strophe Site

然後下載的strophe庫,你應該把框架inside/src/assets/

然後,您應該將腳本標記添加到polyfills.js和main.js

因此

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

末之前的index.html,

你應該把這個聲明語句之前使用的strophe。

declare var Strophe: any; 

這對我的作品!

2)另一種方法是你可以安裝使用

npm install strophe.js 

和node_modules複製strophe.js文件/文件夾strophe.js到您的src /資產上面的文件夾,然後給出路徑索引文件