Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在asp mvc中使用Angular 2时找不到模板_Asp.net Mvc_Angular_Typescript - Fatal编程技术网

Asp.net mvc 在asp mvc中使用Angular 2时找不到模板

Asp.net mvc 在asp mvc中使用Angular 2时找不到模板,asp.net-mvc,angular,typescript,Asp.net Mvc,Angular,Typescript,我正在ASP.NET MVC中使用angular 2 这是“其他”部分: import { Component } from '@angular/core'; @Component({ selector: 'other-app', templateUrl: './app/other/other.component' }) export class OtherComponent { name = "kianoush"; } import { Component } fr

我正在ASP.NET MVC中使用angular 2

这是“其他”部分:

import { Component } from '@angular/core';

@Component({
    selector: 'other-app',
    templateUrl: './app/other/other.component'
})
export class OtherComponent {
    name = "kianoush";
}
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `<h1>My Name is {{name}}</h1>
    <other-app></other-app>`
})
export class AppComponent {

    name = "Kianoush";
}
这是我的应用程序模块:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';
import { OtherComponent } from './other/other.component';

@NgModule({
    imports: [BrowserModule],
    declarations: [
        AppComponent,
        OtherComponent
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }
和此app.component:

import { Component } from '@angular/core';

@Component({
    selector: 'other-app',
    templateUrl: './app/other/other.component'
})
export class OtherComponent {
    name = "kianoush";
}
import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `<h1>My Name is {{name}}</h1>
    <other-app></other-app>`
})
export class AppComponent {

    name = "Kianoush";
}
从'@angular/core'导入{Component};
@组成部分({
选择器:“我的应用程序”,
模板:`我的名字是{{Name}}
`
})
导出类AppComponent{
name=“Kianoush”;
}
这是我的项目的文件夹:

但当我运行项目时,它会在控制台中显示错误:

404找不到

以下是HTML:

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/modernizr-2.6.2.js"></script>
<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>
<base href="/">
<script>
  System.import('app').catch(function(err){ console.error(err); });
</script>

@ViewBag.Title-我的ASP.NET应用程序
System.import('app').catch(函数(err){console.error(err);});

您的模板是否在wwwroot中

您不能只访问文件系统的任何部分,这是出于设计。如果您希望通过请求URL就可以使用模板,请将其放在wwwroot中的正确位置

如果您想通过MVC的控制器系统发回模板,您需要确保路由


有一个关联的控制器方法来处理它。这应该是一个视图控制器方法,可以返回模板的视图。

模板URL的
.html
文件在哪里?@BabarBilal我尝试了一下,但它无法解决URL中的
index.html
中的
标记中没有主文件夹的问题。您的基本标签应设置为
/
@BabarBilal`Loading`这是我正在学习的关于asp mvc 5的根组件。你是怎么做到的?