Having created two components - navbar and login, I am attempting to call a function from the navbar component in the login component. Thus far, my attempts have been unsuccessful...
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'header-Navbar',
templateUrl: './app/navbar/navbar.html',
})
export class Navbar implements OnInit {
constructor(public router: Router) {
}
get(){
if (this.user == null) {
this.showstartupbuttons = true;
this.showsicons = false;
}
else {
this.username = this.user.username;
this.showsicons = true;
this.showstartupbuttons = false;
}
}
In my login.ts file:
import {Component, OnInit} from '@angular/core';
@Component({
templateUrl: './app/login/login.html',
providers:[Navbar]
})
export class Login implements onInit{
ckeditorContent:any;
constructor(public navbar:Navbar) {}
ngOnInit(){
this.navbar.get();
}
I have included providers, but I am uncertain about this process. Could someone please suggest a solution?