使用Angular2项目中的AngularJS(Angular1)模块 [英] Use AngularJS (Angular1) module from Angular2 project

查看:98
本文介绍了使用Angular2项目中的AngularJS(Angular1)模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅启动了一个演示Angular2项目(以前没有使用Angular1/AngularJS的经验.已经从在线快速入门和教程中进行了跟踪和扩展,一切都很好.但是,我现在想使用来自一个专为AngularJS设计的库,没有任何问题!

Just started a demo Angular2 project (no previous experience with Angular1/AngularJS. Have followed and extended from the online quickstart and tutorials, and all was fine. However I'm at the point where I would like to use some components from a library which is designed for AngularJS, and having no end of problems!

关于AngularJS/Angular2兼容性的大多数可用信息都假设您有一个AngularJS项目,您要向其中添加Angular2组件-并非相反-因此,我希望做的事情甚至是不可能的.到目前为止,我尝试过的工作涉及一个基于Angular2快速入门的简单回程项目,其中单个Angular2组件已加载到index.html中.然后,我想将现有库(基于AngularJS)中的组件集成到其中.

Most of the information available about AngularJS/Angular2 compatibility assumes that you have an AngularJS project that you're adding Angular2 components to - not the other way around - so what I'm hoping to do may not even be possible. What I've tried so far involves a simple stripped-back project based on the Angular2 quickstart, with a single Angular2 component that loads into the index.html. I'd then like to integrate components from the existing library (AngularJS-based) into this.

  • 我尝试使用UpgradeAdapter.upgradeNg1Component从库中创建组件并将它们直接添加到我的Angular2组件中

  • I've tried using UpgradeAdapter.upgradeNg1Component to create components from the library and add them directly into my Angular2 component

我尝试通过npm安装angularjs,将其以脚本标记导入到我的index.html中,然后使用UpgradeAdapter.downgradeNg2ComponentUpgradeAdapter.bootstrap的组合将我的Angular2加载为降级模块

I've tried installing angularjs through npm, importing it in a script tag into my index.html and then using a combination of UpgradeAdapter.downgradeNg2Component and UpgradeAdapter.bootstrap to load my Angular2 as a downgraded module

这两个似乎都不起作用-该组件无法显示,并且浏览器控制台告诉我我有一个Uncaught SyntaxError: Unexpected token < Evaluating http://localhost:3000/angular2/upgrade Error loading http://localhost:3000/app/main.js

Neither of these seem to work - the component fails to show, and the browser console tells me I've got an Uncaught SyntaxError: Unexpected token < Evaluating http://localhost:3000/angular2/upgrade Error loading http://localhost:3000/app/main.js

目前,我最好的猜测是这实际上是不受支持的方案,为了使用Angular2的UpgradeAdapter功能,我需要有一个适当的" AngularJS应用程序.有人可以确认吗?还是我在这里想念一些愚蠢的东西?

My best guess at the moment is that this is actually an unsupported scenario, and I need to have a 'proper' AngularJS app in order to use the UpgradeAdapter functionality from Angular2. Can anyone confirm this? Or is there something stupid I'm missing here?

推荐答案

因此,在这种情况下,主要的问题是,似乎升级组件没有包含在基本的Angle 2捆绑包中.添加后:

So the major problem in this case turned out to be the fact that it appears that the upgrade components aren't included as part of the basic angular 2 bundle. After adding:

<script src="node_modules/angular2/bundles/upgrade.min.js"></script>

到我的index.html文件,我看到的错误消失了.

to my index.html file the error I was seeing disappeared.

感谢答案在此为我指明了正确的方向!

Thanks to the answer here for pointing me in the right direction!

这篇关于使用Angular2项目中的AngularJS(Angular1)模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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