title: Angularjs2 'templateUrl' in @Component - how to display razor view
body: <p>How to render a ASP.NET MVC5 Razor View (.cshtml) in the 'templateUrl' in @Component. On using '/Home/Index', the page hangs.</p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { Product } from './model';
  import { InventoryService } from './dataService';
  
  @Component({
      selector: 'my-app',
      template: `&lt;ul&gt;
          &lt;li *ngFor="let product of products"&gt;
              &lt;h4&gt;{{product.getProducts()}}&lt;/h4&gt;
          &lt;/li&gt;
      &lt;/ul&gt;`,
      //templateUrl: '/Home/Index',
      providers: [InventoryService]
  })
  export class AppComponent implements OnInit {
      products: Product[];
  
      constructor(private productService: InventoryService) { }
  
      ngOnInit(): void {
          this.productService.getAll()
              .then(products =&gt; this.products = products);
      }
  }
  </code></pre>
  
  <p>Server Side Routing (RouteConfig.cs):</p>
  
  <pre><code>routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  
              routes.MapRoute(
                  name: "Default",
                  url: "{controller}/{action}/{id}",
                  defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
              );
  </code></pre>
  
  <p>Angular's main page is the MVC's shared _Layout.cshtml file:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;title&gt;@ViewBag.Title - My ASP.NET Application&lt;/title&gt;
      @Styles.Render("~/Content/css")
      @Scripts.Render("~/bundles/modernizr")
  
      &lt;!-- 1. Load libraries --&gt;
      &lt;!-- Polyfill(s) for older browsers --&gt;
  
      &lt;script src="~/node_modules/core-js/client/shim.min.js"&gt;&lt;/script&gt;
      &lt;script src="~/node_modules/zone.js/dist/zone.js"&gt;&lt;/script&gt;
      &lt;script src="~/node_modules/systemjs/dist/system.src.js"&gt;&lt;/script&gt;
  
      &lt;!-- 2. Configure SystemJS --&gt;
      &lt;script src="~/Scripts/systemjs.config.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          System.import('../Scripts/main').catch(function (err)
          {
              console.error(err);
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="navbar navbar-inverse navbar-fixed-top"&gt;
          &lt;div class="container"&gt;
              &lt;div class="navbar-header"&gt;
                  &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                      &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;/button&gt;
  </code></pre>
  
  <p>The web api controller (ProductController.cs) is accessible directly and procuces valid JSON output.</p>
  
  <pre><code>[Route("api/Product/GetProducts")]
          public IEnumerable&lt;ProductJSON&gt; GetProducts()
          {
              IQueryable&lt;ProductJSON&gt; products = _context.Products.Select(
                      p =&gt; new ProductJSON
                      {
                          Name = p.Name,
                          Category = p.Category,
                          Price = p.Price
                      });
              return products.ToList();
          }
  </code></pre>
  
  <p>HomeController.cs is as below:-</p>
  
  <pre><code>public class HomeController : Controller
      {
          public ActionResult Index()
          {
              return View();
          }
  
          public ActionResult About()
          {
              ViewBag.Message = "Your application description page.";
  
              return View();
          }
  
          public ActionResult Contact()
          {
              ViewBag.Message = "Your contact page.";
  
              return View();
          }
      }
  </code></pre>
  
  <p>Index.cshtml is as below:-</p>
  
  <pre><code>@{
      ViewBag.Title = "Home Page";
  }
  
  &lt;my-app&gt;Loading...&lt;/my-app&gt;
  </code></pre>
  
  <p>I am able to access '/Home/Index' path successfully when using 'template', but application hangs and not able to access on using 'templateUrl'</p>
  
  <pre><code>@Component({
      selector: 'my-app',
      template: `&lt;ul&gt;
          &lt;li *ngFor="let product of products"&gt;
              &lt;h4&gt;{{product.getProducts()}}&lt;/h4&gt;
          &lt;/li&gt;
      &lt;/ul&gt;`,
      //templateUrl: '/Home/Index',
      providers: [InventoryService]
  }) 
  </code></pre>