satyender
satyender

Reputation: 837

angularjs 2 set component templateUrl to _layout in MVC

I am new to angular 2. I am using angularjs 2 with asp.net MVC and I want to use my _layout.cshtml(master page) as templateUrl in app.component.

Like in angular 1 i use ng-app="my-app" on _layout page and i can use angular on every content page. How to do that in angularjs 2

Here is my app.component.ts

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

@Component({

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

}) export class AppComponent {

test: string = "";   

}

i want to use my view(cshtml) as templateUrl and directly want to use angularjs on views

Upvotes: 0

Views: 568

Answers (1)

Ali Adravi
Ali Adravi

Reputation: 22723

You need to this about these points when you want to use the cshtml with component

  1. Razor Engine parse you view
  2. When you use as a template in component who will parse it?
  3. Angular Component will provide the data as json

There are many other things which you need to consider

Simple solution is to convert you _layout.cshtml to index.html, because Angular is a SPA application.

I will suggest you to go to this link and try http://blog.stevensanderson.com/2016/10/04/angular2-template-for-visual-studio/

Upvotes: 0

Related Questions