I read that ionic 2 is moving away from bower from one of the posts here. So all third-party libraries will be installed using npm. Once I have it npm installed, I assume I have to change something in webpack.config.js to make sure the library is included and packed by webpack. Is my assumption correct? I’m new to webpack.
Another question I have is that this Parse javascript sdk is using var Parse = require('parse') to load. How do I load that in ionic2/angular2, which has a different loading mechanism? I have searched a lot on this topic and I’m surprising I couldn’t find anything that seemed to address this issue. Perhaps I didn’t use proper search terms.
If the library is written for angular 2, I found it pretty to easy to install and I usually don’t have to mess with anything in webpack.config.js. However, when the library uses a different loading mechanism, i.e., Parse sdk uses require(), that’s where I got stuck.
Hi,
I’m setting up a Project with Angular 2, TypeScript and Parse Server. Thanks for the help so far, that was really valuable!
What I get as well is the following in the Ionic console: ✗ TypeScript error: xxx/app/ParseManager.ts(3,21): Error TS2307: Cannot find module 'parse'.
(I called the Parse class from your example ParseManager).
But it seems to work when running the the browser - I’m able to load data from the server using a Parse.Query.
I installed parse using npm install parse --save
and then also did tsd init tsd install parse --save.
I’m using this as proposed: import {Parse} from 'parse';
Although it works anyway, it would be nice if we could get rid of the error
Yes that’s the same, but Parse is open source now and you can deploy it yourself on AWS, Google App Engine, Heroku, etc. https://github.com/ParsePlatform/parse-server
I think it’s still (or even more?) a good choice as an app backend, especially if you are already using technologies like node.js and MongoDB (which we are).
This does not work for me. But I found another solution.
After installing the package and the typings, I opened the index.js of the node-module ionic-gulp-scripts-copy and added 'node_modules/parse/dist/parse.min.js' to the defaultSrc array.
Then, in my index.html, I included the script above the cordova.js.
Now I just need to declare var Parse: any; in every Component I want to use the SDK in.
For example, in my 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);
I do not think this is the way it should be used, but in the end I can use the SDK pretty easy and without much lines of implementation code.