2016-11-25 68 views
0

我需要重定向到登錄頁面,然後加載Angular2應用程序(不加載它)。 我的項目是基於angular2-quicksart有條件的加載Angular2

當我後裝入angular2 js文件uglifyjs

<script> 
    var cookie = $.cookie(COOKIE_NAME); 
    if (cookie == undefined){ 
     window.location.href = LOGIN_SERVER_URL 
    } else { 
     var head = document.getElementsByTagName('head')[0]; 
     var script = document.createElement('script'); 
     script.src = "build/app/bundle.min.js"; 
     head.appendChild(script); 
     head.innerHTML += ("<script>System.import('app').catch(function(err){ console.error(err); }); <\/script>"); 
    } 
</script> 

此解決方案。 JS被加載並且應用程序正在運行。

當我使用systemjs文件加載角應用,systemjs.config.js已裝入,但應用程序不運行。

`script.src = 「systemjs.config.js」;

我可以動態加載systemjs嗎?

回答

0

這是你應該如何加載系統JS ..

https://github.com/angular/quickstart/blob/master/src/index.html

這是從角快速啓動項目採取。

我提供整個index.html的上下文:

!DOCTYPE html> 
<html> 
    <head> 
    <title>Angular QuickStart</title> 
    <base href="/"> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="styles.css"> 

    <!-- Polyfill(s) for older browsers --> 
    <script src="node_modules/core-js/client/shim.min.js"></script> 

    <script src="node_modules/zone.js/dist/zone.js"></script> 
    <script src="node_modules/systemjs/dist/system.src.js"></script> 

    <script src="systemjs.config.js"></script> 
    <script> 
     System.import('main.js').catch(function(err){ console.error(err); }); 
    </script> 
    </head> 

    <body> 
    <my-app>Loading AppComponent content here ...</my-app> 
    </body> 
</html> 

SystemJS加載了前面,而不是動態的。 System JS的工作是一個動態模塊加載器,但是,由於在加載System JS之前您沒有模塊加載器,因此無法動態加載System JS本身。