如何在Angular 2中使用Twilio Client? [英] How to use Twilio Client in Angular 2?

查看:89
本文介绍了如何在Angular 2中使用Twilio Client?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个我需要实现点击通话"功能的应用程序.因此,为了进行交流,我使用的是 Twilio Client .我已经尝试过此示例.

I am creating an app in which i require to implement Click To Call facility. So for communication I am using Twilio Client. I have tried this example.

现在我需要的是我需要在Angular 2应用程序中实现相同的功能.如何在Typescript中导入 Twilio Client ,如何使用它?

Now all i need it i need to implement the same in my Angular 2 application. How can i import Twilio Client in my Typescript and how can i make use of it?

我正在尝试在

import * as Twilio from 'twilio'

但这不是导入它的正确方法.

but this is not correct method to import it.

推荐答案

此处是Twilio开发人员福音.现在,我们没有任何TypeScript绑定,因此像这样的捆绑将行不通.我正在处理一些绑定,但是与此同时,我建议您像在演示应用程序中一样使用script标签将库包括进来.您可以为此使用我们的Twilio CDN:

Twilio Developer Evangelist here. Right now we don't have any TypeScript bindings and therefore bundling like that won't work. I'm working on some bindings but in the mean time I would suggest you include the library like it's done in the demo application using a script tag. You can use our Twilio CDN for it:

  <script type="text/javascript" src="//media.twiliocdn.com/sdk/js/client/v1.3/twilio.min.js"></script>

之后,您必须让TypeScript知道它.为此,您当前必须使用declare const.不幸的是,在绑定完成之前,这不会给您TypeScript的类型检查带来的任何便利,但至少让您使用它.只需在计划使用Twilio代码的文件中添加以下行:

Afterwards you have to let TypeScript know about it. For this you currently have to use declare const. Unfortunately this won't give you any of the neatness of TypeScript's type-checking until the bindings are done but it at least let's you use it. Just add the following line in the file where you are planning to consume the Twilio code:

declare const Twilio: any;

希望有帮助.

干杯, 多米尼克

这篇关于如何在Angular 2中使用Twilio Client?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆