2016-12-14 102 views
2

我有一个项目的asp.net-mvc与angular2元素。用于启动iis应用程序,该应用程序在Home文件夹中启动index.cshtml(由家庭控制器启动)。所以,我修改的角度,具体如下,索引文件:角度2 system.import错误的路径('应用程序')

<!DOCTYPE html> 
<html> 
<head> 
    <title>Angular QuickStart</title> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="~/styles.css" rel="stylesheet" /> 
    <!-- 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/reflect-metadata/Reflect.js"></script> 
    <script src="~/node_modules/systemjs/dist/system.src.js"></script> 
    <script src="~/systemjs.config.js"></script> 
    <script> 
     System.import('app').catch(function(err){ console.error(err); }); 
    </script> 
</head> 
<body> 
    <my-app>Loading AppComponent content here ...</my-app> 
</body> 
</html> 

现在,当我因为做这个请求启动该应用程序System.import('app')没有找到app文件夹:

zone.js:1382 GET http://localhost/app/main.js 404(未找到)

但是如果我手动调用家庭控制器,正确显示的路径:

http://localhost/my_virtual_path/app/main.js

为什么这种行为? 我可以更改system.import,以便查看相对于项目级别的路径吗?

的完整性,这是system.config.js

/** 
* System configuration for Angular samples 
* Adjust as necessary for your application needs. 
*/ 
(function (global) { 
    System.config({ 
    paths: { 
     // paths serve as alias 
     'npm:': 'node_modules/' 
    }, 
    // map tells the System loader where to look for things 
    map: { 
     // our app is within the app folder 
     app: 'app', 

     // angular bundles 
     '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
     '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
     '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
     '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
     '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
     '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
     '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
     '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 

     // other libraries 
     'rxjs':      'npm:rxjs', 
     'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js', 

     // librerie di terze parti 
     'angular2-datatable': 'npm:angular2-datatable', 
     'lodash': 'npm:lodash/lodash.js', 
    }, 
    // packages tells the System loader how to load when no filename and/or no extension 
    packages: { 
     app: { 
     main: './main.js', 
     defaultExtension: 'js' 
     }, 
     rxjs: { 
     defaultExtension: 'js' 
     }, 


     'angular2-datatable': { 
      main: 'index.js', 
      defaultExtension: 'js' 
     }, 

    } 
    }); 
})(this); 
+0

后systemjs.config.js –

+0

的内容我加入,但我不知道认为这很有帮助,因为我不想改变相对路径。 – FeroX

回答

1

首先,我强烈建议你不要使用asp.net的MVC或类似的东西的角度应用。不需要它。你可以像休息服务一样使用它(asp.net web api)。无论如何,我认为这个问题是来自应用程序的路径(IIS应用程序) 所以你需要这个标记添加到HTML文件头:

<head> 
<base href="/my_virtual_path/"> 
..... 
+0

解决这个问题,但是,我正在寻找一种相对路径的解决方案,以避免在与同事共享文件时不得不更改文件。 – FeroX

+0

你不能像asp.net那样做。因为asp.net在服务器上呈现页面。并注意你不需要使用(/ my_virtual_path /),因为你的路径从根(www.domain.com)开始。不要忘记在Angular2应用中需要基本标签()(请参阅参考资料)。这是你的完整描述。 –

+0

并改变主意,忘记asp.net方法。无需在angularjs,angular2和..... apps中进行服务器端渲染。 –

相关问题