2017-05-04 43 views
0

我使用AngularJS 1.6內的角2的應用程序,並且具有在它(clock)的成分的頁面(panel)上的容器。創建角1.6容器

是否有可能嵌入角2.0應用程序我AngularJS內1.6容器?

這是對ngUpgrade的情景?我想避免學習TypeScript只是爲了演示這種整合。

Controller.js

'use strict'; 
var app = angular.module('app', []); 

app.directive('clock', function() { 
    return { 
    restrict: 'E', 
    scope: { 
     timezone: '@' 
    }, 
    template: '<div>12:00 {{timezone}}</div>' 
    }; 
}); 

app.directive('panel', function() { 
    return { 
    restrict: 'E', 
    transclude: true, 
    scope: { 
     title: '@' 
    }, 
    template: '<div style="border: 3px solid #000000">' + 
     '<div class="alert-box">{{title}}</div>' + 
     '</div>' 
    }; 
}); 

的index.html

<html> 
<head> 
    <meta charset="utf-8"> 

    <script src="/bower_components/angular/angular.js"></script> 
    <script src="js/controller.js"></script> 
</head> 

<body> 

    <div ng-app="app"> 
    <panel title="Title for container"> 
     <clock timezone="PST"></clock> 
    </panel> 
    </div> 

</body> 
</html> 

回答

0

將與ngUpgrade應該滾你需要這樣做!:)然後你可以逐漸引入它。這就是如果你想讓它們在同一個「應用程序」中 - 一個iframe會嵌入Angular應用程序,但不會建議它作爲生產用途。

0

你可以使用一個角1個模板中的iframe,然後本地存儲到2級之間的應用程序訪問數據?

角1模板: <iframe src="URLToAngular2App"></iframe>

+0

是使用'UpgradeAdapter'的選擇呢?使用'iframe'和'localStorage'似乎凌亂 – bobbyrne01

+0

我想這取決於你如何交織希望2級的應用程序?我沒有親自使用過的UpgradeAdapter經驗,但我可能會看看喜歡的文章:http://blog.rangle.io/upgrade-your-application-to-angular-2-with-ng-upgrade / – JonRowley