在Angular 2中使用第三方库(parse.com) [英] Use third party library (parse.com) in Angular 2
问题描述
我正在学习Angular 2,我已经遵循Egghead的教程,但是对于Angular来说,我是相当陌生的.
I am learning Angular 2 and I followed the tutorials of Egghead already, but I am pretty new to everything concerning Angular.
现在,我想做一些更高级的事情,并开始将Angular 2与Parse.com一起使用.
通常,我会通过<script src="//www.parsecdn.com/js/parse-1.6.2.min.js"></script>
将parse.com库包含在index.html页面中,但是我想通过Angular 2编写一个ParseService,可以用来管理后端.
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.
我似乎找不到如何在我要编写的服务中包含和使用Parse的方法. 这是我要用来测试导入的非常基本的代码.
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('', '');
}
}
我需要在页面顶部包括Parse的某种Import,但是我应该从哪里获得必要的库?我已经尝试通过npm
,但是没有成功.已经有人尝试过吗?
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?
推荐答案
uksz是正确的.您必须先通过命令安装组件
uksz was right. You has to first install the component by the command
npm install --save parse
之后,您可以通过键入
import {Parse} from 'parse';
有关更多信息,请参见此链接 https ://forum.ionicframework.com/t/how-to-require-xyz-in-ionic2-angular2/42042
For more info look at this link https://forum.ionicframework.com/t/how-to-require-xyz-in-ionic2-angular2/42042
希望有帮助;)
使用新版本的angular时,此方法停止工作.这是我的新步骤:如何在Angular2中使用解析库
With new version of angular this approach stopped to work. Here is my new step by step: how to use Parse library in Angular2
-
将Parse组件安装到项目中
Install Parse component to the project
npm install parse --save
安装解析类型
Install Parse types
npm install @types/parse --save
导入解析模块
import Parse module
const Parse: any = require('parse');
使用解析模块
use Parse module
Parse.initialize("key");
...
通过智能感知享受它;)
Enjoy it with intellisense;)
这篇关于在Angular 2中使用第三方库(parse.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!