What I want to achieve
I have a CRM panel I am building for practice. That CRM panel has pages, and a navigation on the left side of the screen.
Each page should display the title.
That means that I have to include <h2>title</h2>
in every component template.
Solution that I thouht of
What if I create a component PageBaseComponent
that gets title
:
@Component({
selector: 'app-page-base',
templateUrl: './page-base.component.html',
styleUrls: ['./page-base.component.scss']
})
export class PageBaseComponent implements OnInit {
constructor(private title: string) { }
ngOnInit() {
}
}
And then inherit it whenever I have a new page:
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss']
})
export class HomeComponent extends PageBaseComponent implements OnInit {
constructor() {
super("Dashboard");
}
ngOnInit() {
}
}
And in the template of PageBase
I do
<h1>{{title}}</h1>
And in my component that inherits its I can do something like this IF possible:
<parent-component-html></parent-component-html>
my page info here blab blabla
Is it possible to do? What is the right way to achieve that structure?