通过AspNet-Core-MVC视图呈现时无法加载boot.js

时间:2016-07-07 21:25:29

标签: asp.net-mvc angular

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

{
  "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"
  ]
}
  1. 修改了systemjs.config.js,如下所示加载' app'的boot.js文件映射
  2. 
    
    (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"由Login控制器呈现的视图。
    2. 这" Views / Home / index.cshtml"视图的布局设置为" ./ shared / layout.cshtml"文件 我和#34; Views / Home / index.cshtml"如下
    3. 
      
       @{
              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>
      &#13;
      &#13;
      &#13;

      早些时候我从头开始开发它的是angular2-beta 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
      

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

      enter image description here

1 个答案:

答案 0 :(得分:0)

您正在将脚本输出到“appScripts / or”scripts /“(您的屏幕截图显示了两个不同的”脚本“目录),但是您正在尝试从/ Home / app目录加载boot.js.更改系统.config.ts:

UnmapViewOfFile(bp);

或者更改你的tsconfig outDir属性。