简体   繁体   English

如何在Angular 1.5中注入组件路由器?

[英]How to inject component router in Angular 1.5?

I'm working with Angular 1.5 and trying to migrate from using ui-router in 1.4 to the new Component Router in 1.5. 我正在使用Angular 1.5并试图从使用1.4中的ui-router迁移到1.5中的新组件路由器。

However, when I update to 1.5, I don't see a way to inject '$router' into my configuration. 但是,当我更新到1.5时,我没有看到在我的配置中注入“$ router”的方法。

I know I can download angular_1_router.js from this repository: https://github.com/brandonroberts/angularjs-component-router 我知道我可以从这个存储库下载angular_1_router.js: https//github.com/brandonroberts/angularjs-component-router

But isn't the new router supposed to be included in 1.5? 但是新的路由器应该包含在1.5中吗?

Sorry, there doesn't appear to be much documentation on this. 对不起,似乎没有太多关于此的文档。 There's only the outdated docs that refer to Angular 1.4 and the Angular 2.0 docs . 只有过时的文档引用了Angular 1.4和Angular 2.0文档

When I try using the angular_1_router.js file, I get an $injector:modulerr when trying to use 'ngComponentRouter', so I haven't been able to go that route as a workaround. 当我尝试使用angular_1_router.js文件时,我在尝试使用'ngComponentRouter'时得到$injector:modulerr ,所以我无法将该路由作为一种解决方法。

The new router is in a separate JavaScript file. 新路由器位于单独的JavaScript文件中。 You have to load it in your index.html file. 您必须在index.html文件中加载它。 I am not entirely certain if the 2.0 router works as is with 1.5 or not, but I believe that is supposed to be the case. 我不完全确定2.0路由器是否与1.5一样工作,但我相信应该是这种情况。

It's available here: 它可以在这里找到:

Just loading the js file should be sufficient, no injection is required. 只需加载js文件就足够了,不需要注入。

The latest dev guide is here: https://docs.angularjs.org/guide/component-router 最新的开发指南在这里: https//docs.angularjs.org/guide/component-router

I am currently weighing migrating from ui-router to the new router but finding scant information available. 我目前正在权衡从ui-router迁移到新路由器但是找不到可用的信息。 This article looks to be somewhat helpful: http://geekswithblogs.net/shaunxu/archive/2015/03/30/horror-migrating-angular-ui-router-to-angular-new-router.aspx , but it's quite dated. 这篇文章看起来有点帮助: http//geekswithblogs.net/shaunxu/archive/2015/03/30/horror-migrating-angular-ui-router-to-angular-new-router.aspx ,但它已经过时了。

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

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