Use AngularJS (Angular1) module from Angular2 project

前端 未结 2 1659
无人及你
无人及你 2021-02-05 19:21

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. Howe

相关标签:
2条回答
  • 2021-02-05 20:07

    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>

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

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

    0 讨论(0)
  • 2021-02-05 20:08

    Here is a working plunkr describing how to mix Angular1 and Angular2 elements:

    • http://plnkr.co/edit/yMjghOFhFWuY8G1fVIEg?p=preview

    An important point is to bootstrap your main component on the UpgradeAdapter. This way all elements are available in providers (services / factories) and in directives (components / directives):

    upgrade.bootstrap(document.body, ['heroApp']);
    

    These two answers could help you:

    • angular 1.x and angular2 together
    • How to inject upgraded Angular 1 service/factory to Angular 2 component in ES5?
    0 讨论(0)
提交回复
热议问题