【发布时间】:2017-08-01 17:09:45
【问题描述】:
我在 asp mvc 5 中使用 angular 2。
我需要在视图中显示<my-app> </my-app> 内容。
app.component :
import { Component } from '@angular/core';
import 'rxjs/Rx'; // Load all features
import { ROUTER_PROVIDERS, RouteConfig, ROUTER_DIRECTIVES } from '@angular/router';
import { OtherComponent } from './other/other.component';
@Component({
selector: 'my-app',
template: `<h1>My Name is {{name}}</h1>
<other-app></other-app>`,
})
@RouteConfig([
{ path: '/other', name: 'other', component: OtherComponent }
])
export class AppComponent {
name = "Kianoush";
}
它向我显示错误:
严重性代码描述项目文件行抑制状态 错误构建:模块 '"F:/MyProject/angfinal/angfinal/node_modules/@angular/router/index"' 没有导出的成员 'ROUTER_PROVIDERS'。 angfinal F:\MyProject\angfinal\angfinal\app\app.component.ts 3
。
严重性代码描述项目文件行抑制状态 错误构建:模块'“F:/MyProject/angfinal/angfinal/node_modules/@angular/router/index”'没有导出成员'RouteConfig'。 angfinal F:\MyProject\angfinal\angfinal\app\app.component.ts 3
.
严重性代码描述项目文件行抑制状态 错误 TS2305 模块 '"F:/MyProject/angfinal/angfinal/node_modules/@angular/router/index"' 没有导出的成员 'ROUTER_PROVIDERS'。 TypeScript 虚拟项目 F:\MyProject\angfinal\angfinal\app\app.component.ts 3 活动
.
严重性代码描述项目文件行抑制状态 错误 TS2305 模块 '"F:/MyProject/angfinal/angfinal/node_modules/@angular/router/index"' 没有导出的成员 'RouteConfig'。 TypeScript 虚拟项目 F:\MyProject\angfinal\angfinal\app\app.component.ts 3 活动
.
其他组件:
import { Component } from '@angular/core';
@Component({
selector: 'other-app',
templateUrl: './app/other/other.component.html'
})
export class OtherComponent {
name = "kianoush";
}
和标题:
<head>
<base href="/">
<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>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
和配置:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "NotFound",
url: "{*catchall}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
我如何在视图中显示other.component.html,我该如何解决这个问题??
【问题讨论】:
-
你应该根据错误信息“import 'rxjs/Rx'”关注这一行;
-
@Pengyy 我删除了这一行但仍然显示错误
标签: asp.net angularjs asp.net-mvc angular angular2-routing