angularjs 2在MVC中将组件templateUrl设置为_layout

时间:2017-08-24 15:30:24

标签: angular

我是角色2的新手。我在asp.net MVC中使用angularjs 2,我想在app.component中使用我的_layout.cshtml(母版页)作为templateUrl。

就像角度1一样,我使用ng-app =" my-app"在_layout页面上,我可以在每个内容页面上使用角度。如何在angularjs 2

中做到这一点

这是我的app.component.ts

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

@Component({

selector: 'my-app',
templateUrl:'/views/shared/_layout.cshtml'//i want to do that

}) 导出类AppComponent {

test: string = "";   

}

我想将我的视图(cshtml)用作templateUrl并直接想在视图上使用angularjs

1 个答案:

答案 0 :(得分:0)

当您想要将cshtml与组件

一起使用时,您需要了解这些要点
  1. Razor Engine解析您查看
  2. 当您在将要解析它的组件中用作模板时?
  3. Angular Component将提供数据为json
  4. 您还需要考虑许多其他事项

    简单的解决方案是将_layout.cshtml转换为index.html,因为Angular是一个SPA应用程序。

    我建议您转到此链接并尝试http://blog.stevensanderson.com/2016/10/04/angular2-template-for-visual-studio/

相关问题