MVC - Angular 2

如何:从 ASP.NET 核心控制器调用 ANGULAR 2 HTML / JS 组件:

我们调用 HTML 而不是返回 View()

 return File("~/html/About.html", "text/html");

并在 html 中加载角度分量。在这里,我们可以决定是否要使用相同或不同的模块。取决于情况。

wwwroot 文件/ HTML / About.html

    <!DOCTYPE html>
<html>
  <head>
    <title>About Page</title>
    <base href="/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
      <link href="../css/site.min.css" rel="stylesheet" type="text/css"/>

    <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/systemjs/dist/system.src.js"></script>

    <script src="../systemjs.config.js"></script>
    <script>
      System.import('../main.js').catch(function(err){ console.error(err); });
    </script>
  </head>

  <body>
    <aboutpage>Loading AppComponent here ...</aboutpage>
  </body>
</html>

(*)此种子已经需要加载整个资源列表

如何:调用 ASP.NET Core Controller 以显示支持 Angular2 的 MVC 视图:

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

@Component({
  selector: 'aboutpage',
  templateUrl: '/home/about',
})
export class AboutComponent  {
    
}