admin管理员组文章数量:1333431
What's the best way of importing and using JavaScript code within TypeScript?
I'm trying to use stuff like Bootstrap's modal.js within an Angular 2 Component written using TypeScript.
UPDATE:
The solution as suggested was to create a type declaration d.ts file for the js file to forward delcare things I needed to use, then the referenced js file implementation was used at runtime.
Shame there isn't a more automatic direct way but it gets the job done. For many mon frameworks these d.ts type declarations are available as mentioned via . I also didn't need to ment style reference the d.ts as it was already included in my piled ts files.
What's the best way of importing and using JavaScript code within TypeScript?
I'm trying to use stuff like Bootstrap's modal.js within an Angular 2 Component written using TypeScript.
UPDATE:
The solution as suggested was to create a type declaration d.ts file for the js file to forward delcare things I needed to use, then the referenced js file implementation was used at runtime.
Shame there isn't a more automatic direct way but it gets the job done. For many mon frameworks these d.ts type declarations are available as mentioned via http://definitelytyped/tsd. I also didn't need to ment style reference the d.ts as it was already included in my piled ts files.
Share Improve this question edited Apr 21, 2017 at 13:19 user663031 asked Feb 18, 2016 at 13:40 Chris SnowdenChris Snowden 5,0021 gold badge26 silver badges34 bronze badges1 Answer
Reset to default 5You can use type declaration or write your own. Take a look on this project http://definitelytyped/tsd/
It has type definitions for many popular libraries. And also for angular-ui-bootstrap
.
Then you can reference definition in Typescript like this:
///<reference path="../typings/angular-ui-bootstrap/angular-ui-bootstrap.d.ts"/>
In general you basically reference a library, then in typescript you should reference a type definition or provide your own declaration, like
declare function hex_md5(value: string): string;
if you have javascript function hex_md5
defined somewhere above.
本文标签: angularCalling JavaScript functions from TypeScriptStack Overflow
版权声明:本文标题:angular - Calling JavaScript functions from TypeScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742314963a2451629.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论