How to embed a self-contained Angular 2 application inside of an Angular 1 application

后端 未结 1 1953
攒了一身酷
攒了一身酷 2021-01-18 18:12

Note: I am NOT upgrading an ng1 app. I\'m trying to get an ng1 and ng2 app to live side-by-side (or rather nested).

We have roughly the following html showi

相关标签:
1条回答
  • 2021-01-18 18:46

    This question itself can raise thousand of other questions.It is not at all easy to answer this question so fully because you are talking about two major MVC based architectures(Angular1 and Angular2) together.

    See how to use angular2 within angular1. Successfully I can bootstrap angular2 app within angular1 app.

    It is extremely important to know how you have implemented your angular1 architecture. But if you are angular1&2 guy, you'd probably find ways on your own.

    Angular2 App within Angular1 App

    Index.html

    <body ng-app="app" ng-controller="appController">
        <header>{{myValue}}</header>   //belongs to angular1
    
        <div ng-non-bindable>
          <my-app></my-app>
    
          <!-- angular 2 app bootstrapping -->
        </div>
    
        <footer>Angular 1 Stuff</footer>
    
        <script>
            var app=angular.module("app",[]);
    
            app.controller("appController",function($scope){
              $scope.myValue="Nyks";
            })
        </script>
    
    0 讨论(0)
提交回复
热议问题