I'm having an error with ERROR TypeError: Cannot read property 'deleteData' of undefined. It seems that my service cannot use the functions of the other service I've injected.
this is my util.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class UtilService {
deleteData() {
localStorage.removeItem('token');
}
}
this is my another service which is the auth.service.ts
import { Injectable } from '@angular/core';
import { UtilService } from "./util.service";
@Injectable()
export class AuthService {
constructor (private util: UtilService) { }
logout() { this.util.deleteData() }
}
this is the component where i've used the auth.service.ts
import { Component } from '@angular/core';
import { AuthService } from "../../services";
@Component({
selector: 'app-header',
template: require('./header.component.pug'),
styles: [require('./header.component.scss')]
})
export class HeaderComponent {
constructor(
private router: Router,
private auth: AuthService
) {}
userLogout() { this.auth.logout();}
}
this is my error enter image description here