2016-07-07 125 views
0

enter image description here当通过AspNet-Core-MVC视图呈现时,无法加载boot.js 我尝试创建ApsNet核心+ Angular2 RC4应用程序。以下是我为构建应用程序所做的步骤 1.从angular(RC4)快速入门教程创建/更新Package.json,systemjs.config.js,typings.json和tsconfig.json,并对其进行了小的更改根据我的需要 2.将所有的angular2组件置于脚本文件夹下,并将tsconfig.json放置在相同的位置。但是指定outDir属性将所有经过转换的.js文件移动到wwwroot/appScripts /文件夹。当通过AspNet-Core-MVC视图呈现时,无法加载boot.js

{ 
    "compilerOptions": { 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "module": "commonjs", 
    "noEmitOnError": true, 
    "noImplicitAny": true, 
    "outDir": "../wwwroot/appScripts/", 
    "removeComments": false, 
    "sourceMap": true, 
    "suppressImplicitAnyIndexErrors": true, 
    "moduleResolution": "node", 
    "target": "es6" 
    }, 
    "compileOnSave": true, 
    "exclude": [ 
    "node_modules", 
    "wwwroot" 
    ] 
} 
  • 修改为下面的systemjs.config.js加载boot.js文件为 '应用' 映射
  • (function (global) { 
     
        // map tells the System loader where to look for things 
     
        var map = { 
     
         'app': 'app', // 'dist', 
     
         '@angular': 'lib/@angular', 
     
         'rxjs': 'lib/rxjs' 
     
        }; 
     
        // packages tells the System loader how to load when no filename and/or no extension 
     
        var packages = { 
     
         'app': { main: 'boot.js', defaultExtension: 'js' }, 
     
         'rxjs': { defaultExtension: 'js' } 
     
        }; 
     
        var ngPackageNames = [ 
     
         'common', 
     
         'compiler', 
     
         'core', 
     
         'http', 
     
         'platform-browser', 
     
         'platform-browser-dynamic', 
     
         'router', 
     
         'router-deprecated', 
     
         'upgrade', 
     
        ]; 
     
        // Add package entries for angular packages 
     
        ngPackageNames.forEach(function (pkgName) { 
     
         packages['@angular/' + pkgName] = { main: pkgName + '.umd.js', defaultExtension: 'js' }; 
     
        }) ; 
     
        var config = { 
     
         map: map, 
     
         packages: packages 
     
        } 
     
        System.config(config); 
     
    })(this);

    1. 当应用程序加载时,它首先登录到登录页面,然后通过身份验证重定向到“Views/Home/index.cshtml”视图由登录控制器呈现。
    2. 这种“查看/主页/ index.cshtml”的观点是有/设置为“./shared/layout.cshtml”文件 我的‘查看/主页/ index.cshtml’的布局下,如以下

    @{ 
     
         ViewData["Title"] = "Home Page"; 
     
         Layout = "_Layout"; 
     
        } 
     
        
     
        <!-- IE required polyfills, in this exact order --> 
     
        <script src="~/lib/core-js/client/shim.min.js"></script> 
     
        <script src="~/lib/zone.js/dist/zone.js"></script> 
     
        <script src="~/lib/reflect-metadata/Reflect.js"></script> 
     
        <script src="~/lib/systemjs/dist/system.src.js"></script> 
     
        <!-- 2. Configure SystemJS --> 
     
        <script src="systemjs.config.js"></script> 
     
        
     
        <script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script> 
     
        
     
        <script> 
     
         System.import('app').catch(function (err) { console.error(err); }); 
     
        </script>

    早些时候,当我开发了从划痕是与angular2 - β版本17,但现在我已经迁移到Angular2 RC4。 现在的问题,我面对的应用程序无法加载boot.js文件,我收到以下错误在浏览器控制台

    menu.js:103 Uncaught TypeError: $(...).tooltip is not a function 
    http://localhost:55413/Home/app/boot.js Failed to load resource: the server responded with a status of 404 (Not Found) 
    Index:54 Error: Error: XHR error (404 Not Found) loading http://localhost:55413/Home/app/boot.js 
         at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:55413/lib/zone.js/dist/zone.js:769:30) 
         at ZoneDelegate.invokeTask (http://localhost:55413/lib/zone.js/dist/zone.js:356:38) 
         at Zone.runTask (http://localhost:55413/lib/zone.js/dist/zone.js:256:48) 
         at XMLHttpRequest.ZoneTask.invoke (http://localhost:55413/lib/zone.js/dist/zone.js:423:34) 
        Error loading http://localhost:55413/Home/app/boot.js(anonymous function) @ Index:54 
    http://localhost:55413/app/boot.js Failed to load resource: the server responded with a status of 404 (Not Found) 
    Index:84 Error: Error: XHR error (404 Not Found) loading http://localhost:55413/app/boot.js 
         at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:55413/lib/zone.js/dist/zone.js:769:30) 
         at ZoneDelegate.invokeTask (http://localhost:55413/lib/zone.js/dist/zone.js:356:38) 
         at Zone.runTask (http://localhost:55413/lib/zone.js/dist/zone.js:256:48) 
         at XMLHttpRequest.ZoneTask.invoke (http://localhost:55413/lib/zone.js/dist/zone.js:423:34) 
        Error loading http://localhost:55413/app/boot.js 
    

    为什么应用程序不能识别/加载启动.js文件,我指向加载它的错误路径?我需要做什么改变?

    enter image description here

    回答

    0

    你输出你的脚本“appScripts /或‘脚本/’(你的屏幕截图显示两个不同的‘脚本’目录),但是你正试图从/ home加载boot.js/。app目录更改system.config.ts:

    var packages = { 
         'app': { main: 'scripts/boot.js', defaultExtension: 'js' }, 
         'rxjs': { defaultExtension: 'js' } 
        }; 
    

    或更改tsconfig OUTDIR财产

    +0

    在快照appScripts指输出目录,脚本指的是我的实际角度成分存在我的打字稿文件夹以及tsco nfig.json文件。我尝试通过将appScripts作为boot.js的前缀来提示:{main:'appScripts/boot.js',defaultExtension:'js'},但仍然收到相同的错误错误:XHR错误(404 Not Found)加载http :// localhost:55413/Home/app/appScripts/boot.js 索引:84错误:错误:XHR错误(404 Not Found)加载http:// localhost:55413/app/appScripts/boot.js(...) – Krishnan