2016-02-29 46 views
2

我试图导入JS SDK成离子2应用程序,但我不断收到解析未定义如何导入解析JS SDK成离子2公测

离子1.x中,解析JS SDK是通过

<script ..parse.js </script>

,并公开为全局变量,如何在离子2做进口,现在用的是NPM模块,并试图

import * as parse from 'parse'

回答

0

寻找解决方案后,我想出了自己的解决方案。 安装软件包和类型后,我打开node-module ionic-gulp-scripts-copy的index.js,并将'node_modules/parse/dist/parse.min.js'添加到defaultSrc阵列。 然后,在我的index.html中,我包含了cordova.js上方的脚本。 现在我只需要declare var Parse: any;中的每个组件我想使用的SDK中 例如,在我的app.ts:

import {Component} from '@angular/core'; 
 
import {Platform, ionicBootstrap} from 'ionic-angular'; 
 
import {StatusBar} from 'ionic-native'; 
 
import {TabsPage} from './pages/tabs/tabs'; 
 

 
import{LoginPage} from './pages/login/login'; 
 
declare var Parse: any; 
 

 
@Component({ 
 
    template: '<ion-nav [root]="rootPage"></ion-nav>', 
 
}) 
 
export class MyApp { 
 

 
    private rootPage: any; 
 
    private parse; 
 
    constructor(private platform: Platform) { 
 
    //this.rootPage = TabsPage; 
 
    this.rootPage = LoginPage; 
 
    platform.ready().then(() => { 
 
     console.log("Platform ready!"); 
 
     // Okay, so the platform is ready and our plugins are available. 
 
     // Here you can do any higher level native things you might need. 
 
     StatusBar.styleDefault(); 
 

 
     Parse.initialize('myStartUp', 'someKey'); 
 
     Parse.serverURL = 'http://localhost:1337/parse'; 
 
    }); 
 
    } 
 
} 
 

 
ionicBootstrap(MyApp);

我不认为这是它的方式应该使用,但最终我可以使用SDK很容易,没有太多的实现代码行。

1

npm install parse --save项目目录中使用

import { Parse } from 'parse';

这是更好地创建一个解析提供商

然后导入解析。

您可以使用此入门模板作为指导。这是一个简单的GameScores离子应用程序,让你开始。

https://github.com/Reinsys/Ionic-Parse

它展示了如何创建和读取解析服务器的数据。我还包括使用离子无限滚动滚动的分页。