使用Angular2项目中的AngularJS(Angular1)模块

编程入门 行业动态 更新时间:2024-10-26 12:26:28
本文介绍了使用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.downgradeNg2Component和UpgradeAdapter.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 localhost:3000/angular2/upgrade Error loading 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 localhost:3000/angular2/upgrade Error loading 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)模块

本文发布于:2023-11-23 02:10:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619711.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   项目   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!