首页 文章

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

提问于
浏览
0

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

就像在角度1中我在_layout页面上使用ng-app =“my-app”,我可以在每个内容页面上使用角度 . 如何在angularjs 2中做到这一点

这是我的app.component.ts

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

@零件({

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

})export class AppComponent {

test: string = "";

}

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

1 回答

  • 0

    当您想要将cshtml与组件一起使用时,您需要了解这些要点

    • Razor Engine解析您的视图

    • 当您在将要解析它的组件中用作模板时?

    • Angular Component将以json的形式提供数据

    您还需要考虑许多其他事项

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

    我建议你去这个链接尝试http://blog.stevensanderson.com/2016/10/04/angular2-template-for-visual-studio/

相关问题