简体   繁体   English

如何在angular2-meteor项目中正确添加使用Meteor包?

[英]How to add correctly use Meteor package in a angular2-meteor project?

I am writing an angular2-meteor program. 我正在编写一个angular2流星程序。

When I am using urigo:angular2-meteor package, I add reference path like this: 当我使用urigo:angular2-meteor软件包时,我添加了如下引用路径:

/// <reference path="../typings/angular2-meteor.d.ts" />

The question is: can I use other normal meteor packages in a angular2-meteor project? 问题是:我可以在angular2-meteor项目中使用其他普通的流星包吗? Or I can only use some packages written for angular2-meteor specifically. 或者我只能使用一些专门为angular2-meteor编写的软件包。

For example, if I want to use yuukan:streamy , how can I use it correctly? 例如,如果我想使用yuukan:streamy ,如何正确使用它? Right now, I have one line code 现在,我有一个行代码

Streamy.broadcast('hello', {data: 'world!'});

When I compile it, it shows: Cannot find name 'Streamy'. 当我编译它时,它显示: Cannot find name 'Streamy'.

Thanks! 谢谢!

you can use all the libraries from meteor. 您可以使用流星的所有库。

you will have 2 choices. 您将有2个选择。

  1. find the streamy definition file (streamy.d.ts) if it exists. 查找流定义文件(streamy.d.ts)(如果存在)。 This will give you autocompletion and compile errors if you misuse streamy functions. 如果您滥用流函数,这将给您自动补全和编译错误。
  2. If you dont find a definition file than just add declare var Streamy at the top of the file you want to use it. 如果您找不到定义文件,而只是在要使用的文件顶部添加declare var Streamy The library is already there if you add it via atmosphere . 如果通过atmosphere添加库,则该库已经存在。 But typescript does not know about it. 但是打字稿对此一无所知。 By declaring the variable you tell typescript that this exists and it wont complain when compiling. 通过声明变量,您告诉打字稿它存在,并且在编译时不会抱怨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM