2016-11-07 61 views
0

我想在sails應用程序中正確創建一個angular2應用程序。Angular2 in sails應用程序配置

我想AngularApp下/管理URL運行

我做了什麼:

  1. 創建ManagementController.js:
module.exports = { 
    index: function (req, res) { 
     res.locals.layout = 'layouts/angular'; 
     return res.view('angular/angular-start.ejs'); 
    } 
}; 
  • 根據views/layouts/angular.ejs創建角佈局:
  • <!DOCTYPE html> 
    <html> 
    <head> 
        <title>Reloyalty Administration Dashboard</title> 
    
        <!-- Viewport mobile tag for sensible mobile support --> 
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 
        <link rel="icon" href="/favicon.ico"> 
    
        <!-- Common Scripts--> 
        <script src="/common/js/jquery-1.11.3.min.js"></script> 
    
        <!--SCRIPTS--> 
        <!--SCRIPTS END--> 
    
        <script> 
         // SystemJS 
         // config goes here 
        </script> 
    
        <!-- end AngularJS 2--> 
    </head> 
    
    <body> 
    
    <%- body %> 
    
    
    </body> 
    </html> 
    
  • 創建下視圖/角度/角start.ejs

    加載的圖...

  • 創建的文件夾資產/管理在我的角度應用程序將是

  • 創建資產/管理/ 應用文件夾

  • 加入copy.js:

    grunt.config.set( '複製',{ 開發:{ 文件:[{ 擴大:真實, CWD:」 ./assets', SRC :['/', '!/ .coffee', '! /.ts', '!/ .LESS' ], DEST:「.TMP /公衆 }]} , 編譯:{ 文件:[{ 擴大:真實, CWD: '的.tmp /公衆', SRC :[」 /'], DEST: 'WWW' }] }, angular_node_deps:{ 文件:[{ 擴大:真, CWD:, SRC'。 ':[ ' ./ node_modules/es6-shim/es6-shim.min.js', './node_modules/systemjs/dist/system-polyfills.js', './node_modules/systemjs/dist/system.src.js', './node_modules/zone.js/dist/zone.js' , './node_modules/reflect-metadata/Reflect.js', ' ./node_modules/rxjs//的.js', 」 ./node_modules/@angular/core/bundles/core.umd.js' , './node_modules/@angular/compiler/bundles/compiler.umd.js', './node_modules/@angular/common/bundles/common.umd.js', './node_modules/@angular/ platform-b​​rowser-dynamic/bundles/platform-b​​rowser-dynamic.umd.js', './node_modules/@angular/platform-b​​rowser/bundles/platform-b​​rowser.umd。js' ], dest:'.tmp/public/js' }] } });

  • 什麼我現在做的有它運行正常......我一直在嘗試所有的日子,所以我不想現在就張貼我的代碼,使這項工作,但只要按照您的指示,因爲我有在我的代碼中做了很多更改,我不理解它。

    回答

    0

    我不確定你在做什麼,但我最近成功地將一個簡單的Angular應用程序嵌入到現有的應用程序中。

    我所做的只是使用AngularCLI生成一個新項目,然後在現有應用程序中嵌入捆綁的* .js文件(由ng build命令生成的文件)和根html模板,盒子。