简体   繁体   English

Angular4 + Angular CLI 支持 Javascript AngularJS?

[英]Angular4 + Angular CLI supporting Javascript AngularJS?

Is it possible to get angular4 + angular CLI to support Javascript files?是否有可能获得 angular4 + angular CLI 来支持 Javascript 文件?

I have a legacy angularJS application written in javascript that I want to import components from in my Angular4 application using the upgrade module.我有一个用 javascript 编写的遗留 angularJS 应用程序,我想使用升级模块从我的 Angular4 应用程序中导入组件。 The current problem I am facing is that the angularCLI doesn't seem to be loading/building the included javascript components/files in the project that I added.我目前面临的问题是 angularCLI 似乎没有在我添加的项目中加载/构建包含的 javascript 组件/文件。

I am currently following this guide which doesn't mention getting javascript angularjs components into angular4: https://angular.io/guide/upgrade我目前正在关注本指南,其中没有提到将 javascript angularjs 组件放入 angular4: https ://angular.io/guide/upgrade

Thanks!谢谢!

Anything you can do with Angular in TypeScript, you can also do in JavaScript.任何你可以在 TypeScript 中使用 Angular 做的事情,你也可以在 JavaScript 中做。 Translating from one language to the other is mostly a matter of changing the way you organize your code and access Angular APIs.从一种语言翻译成另一种语言主要是改变组织代码和访问 Angular API 的方式。

you may find documentation here .您可以在此处找到文档。

you can use declare keyword in typescript .您可以在typescript中使用declare关键字。 Try link your old angularjs file into html with script tag.尝试使用脚本标记将旧的 angularjs 文件链接到html Then declare that component which you want to use from old angularjs in Angular 4/typescript like:然后在 Angular 4/typescript 中declare要从旧的 angularjs 使用的组件,例如:

declare var YourComponent;

More about declare http://blogs.microsoft.co.il/gilf/2013/07/22/quick-tip-typescript-declare-keyword/有关declare的更多信息http://blogs.microsoft.co.il/gilf/2013/07/22/quick-tip-typescript-declare-keyword/

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

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