Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use third party library (parse.com) in Angular 2

I am learning Angular 2 and I followed the tutorials of Egghead already, but I am pretty new to everything concerning Angular.

Now I want to do something more advanced and start using Parse.com with Angular 2. Normally I would include the parse.com library in the index.html page via <script src="//www.parsecdn.com/js/parse-1.6.2.min.js"></script>, but I want to write a ParseService via Angular 2 that I can use to manage the backend.

I can't seem to find how to include and use Parse in the service I want to write. This is the very basic code I want to use to test the import.

import {Injectable} from 'angular2/core';
import {Parse} from '.../...'; // <-- This is what I want to do

@Injectable()
export class ParseService {
    constructor() {
        console.log('Creating ParseService');

        Parse.initialize('', '');
    }
}

I need some kind of Import at the top of the page including Parse, but from where should I get the necessary library? I already tried via npm but without success. Anyone already tried this?

like image 604
ThijsM Avatar asked Jan 19 '16 21:01

ThijsM


1 Answers

uksz was right. You has to first install the component by the command

npm install --save parse

After that you can import it as any other component by typing

import {Parse} from 'parse';

For more info look at this link https://forum.ionicframework.com/t/how-to-require-xyz-in-ionic2-angular2/42042

Hope it helps;)

UPDATED

With new version of angular this approach stopped to work. Here is my new step by step: how to use Parse library in Angular2

  1. Install Parse component to the project

    npm install parse --save
    
  2. Install Parse types

    npm install @types/parse --save
    
  3. import Parse module

    const Parse: any = require('parse');
    
  4. use Parse module

    Parse.initialize("key");
    ...
    

Enjoy it with intellisense;)

like image 110
Jan Kuta Avatar answered Oct 15 '22 19:10

Jan Kuta