【问题标题】:angularjs 2 set component templateUrl to _layout in MVCangularjs 2在MVC中将组件templateUrl设置为_layout
【发布时间】:2017-08-24 15:30:23
【问题描述】:

我是 angular 2 的新手。我正在将 angularjs 2 与 asp.net MVC 一起使用,我想在 app.component 中使用我的 _layout.cshtml(master page) 作为 templateUrl。

就像在 angular 1 中一样,我在 _layout 页面上使用 ng-app="my-app" 并且我可以在每个内容页面上使用 angular。如何在 angularjs 2 中做到这一点

这是我的 app.component.ts

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

@组件({

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

}) 导出类 AppComponent {

test: string = "";   

}

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

【问题讨论】:

    标签: angular


    【解决方案1】:

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

    1. Razor 引擎解析您查看的内容
    2. 当您在组件中用作模板时,谁来解析它?
    3. Angular 组件将以 json 格式提供数据

    还有很多事情需要考虑

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2021-05-19
      • 1970-01-01
      • 1970-01-01
      • 2014-08-09
      • 2014-10-01
      相关资源
      最近更新 更多