我正在使用mvc .Net结合最新的角度(5.2.10)。问题是我无法启动和运行Angular。
Angular app文件位于' app'夹。 ' _Layout.cshtml'位于内部视图/共享文件夹中。
_Layout.cshtml:
<!DOCTYPE html>
<html>
<head>
<base href="/" />
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Polyfill(s) for older browsers -->
<script type="text/javascript" src="~/node_modules/core-js/client/shim.min.js"></script>
<script type="text/javascript" src="~/node_modules/zone.js/dist/zone.js"></script>
<script type="text/javascript" src="~/node_modules/systemjs/dist/system.src.js"></script>
<script type="text/javascript" src="~/systemjs.config.js"></script>
<script type="text/javascript">
System.import('app/main.js').catch(function (err) { console.error(err); });
</script>
</head>
<body>
<div>
@RenderBody()
</div>
</body>
</html>
systemjs.config.js:
(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'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
defaultExtension: 'js',
meta: {
'./*.js': {
loader: "systemjs-angular-loader.js"
}
}
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
我得到的错误是:
Error: Fetch error: 404 Not Found (systemjs-angular-loader.js)
Instantiating http://www.nlgdevelopment.com/systemjs-angular-loader.js
Loading http://www.nlgdevelopment.com/systemjs-angular-loader.js
Instantiating http://www.nlgdevelopment.com/app/main.js
Loading app/main.js
at fetch.js:37
at ZoneDelegate.invoke (zone.js:388)
at Zone.run (zone.js:138)
at zone.js:872
at ZoneDelegate.invokeTask (zone.js:421)
at Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
&#39; Systemjs-角loader.js&#39;和&#39; systemjs.config.js&#39;文件位于同一级别(根路径)。我遵循了官方Angular网站提供的快速入门指南,但出了点问题。
答案 0 :(得分:0)
如果这是一个新项目,我建议使用dot net命令删除它并开始一个新项目:
dotnet new angular -o my-new-app
这将使用Angular CLI生成您的应用。 基本上,您的MVC应用程序根本不包含任何“Views”文件夹,甚至不包含_Layout.cshtml页面。所有客户端逻辑和模板都存储在“Client App”文件夹中。