I am building an Angular 4 app integrated with MVC 5. I am creating a Movie component that has two templates. One to list the movies and second is to add the movies. How do I handle the render of either of the template using the Movie component. Currently the templateURL is containing only one template. The code is as below
app.component.ts
import { Component } from "@angular/core";
@Component({
selector: "mrdb-app",
templateUrl: "./Scripts/app/app.component.html"
})
export class AppComponent {
pageTitle: string = "Movies Review Database";
}
app.component.html
<div>
<h1>{{pageTitle}}</h1>
<app-movie></app-movie> //This selector belongs to movie component
</div>
movie.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-movie',
templateUrl: './Scripts/movie/movie-list.component.html'
})
export class MovieComponent implements OnInit {
pageTitle: string = "Movie List";
constructor() { }
ngOnInit() {
}
}
Movie-list.component.html
//Assume I have written a logic to display list of movies
Movie-Add.component.html
//Assume I have written a html for data entry screen
Movie Module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MovieComponent } from './movie.component';
@NgModule({
imports: [
CommonModule
],
declarations: [MovieComponent],
exports: [MovieComponent]
})
export class MovieModule { }
ng-templatetags inside a component template and you can then access them using @ViewChildren and then render them usingNgTemplateOutletdirective