0

i am using angular 4 in mvc architecture . wheneve i gona pass mvc view in template url in the app.component.ts file it shows some error. can i pass the mvc view in the type script file or i have to create a html file in app folder.

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

@Component({
    selector: 'my-app',
    templateUrl: '/Home/Index.cshtml',
})
export class AppComponent  {
    name = '';
}
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="Registeration">
    <my-app>Loading AppComponent content here ...</my-app>
    <input type="text" [(ngmodel)]="name"/>
    <p>{{name}}</p>
 
</div>

5
  • are you using angular-cli? Commented Dec 6, 2017 at 13:38
  • i am new in angular 4 . I have run angular cli command for just set up the angular 4 in visual studio solution. Commented Dec 6, 2017 at 13:41
  • What you want to do? Commented Dec 6, 2017 at 13:53
  • Read it, It may help stackoverflow.com/questions/35762515/is-angular2-mvc Commented Dec 6, 2017 at 13:55
  • I just want to use app.component.ts file for index.cshtml . and i think the way i am passing the view into template url is not correct . I mean is it the right way to pass the mvc view in template url. like we can pass the html file in template url as follows './app.component.html' Commented Dec 6, 2017 at 13:57

1 Answer 1

0

Possible solution

app.component.ts

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html', 
  styleUrls: ['./app.component.css']
})

app.component.html

<child-cmp></child-cmp> <------ selector of child component

child.component.ts

@Component({
  selector: 'child-cmp',         <----pass this selector to view this component
  templateUrl: './child.component.html', 
  styleUrls: ['./child.component.css']
})

name = 'child';

Put your index.cshtml file in child.component.html

child.component.html

<div id="Registeration">   
    <input type="text" [(ngmodel)]="name"/>
    <p>{{name}}</p>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.