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  {
    
}