我遇到ERROR TypeError错误:无法读取未定义的属性'deleteData'。看来我的服务不能使用我注入的其他服务的功能。
这是我的util.service.ts
import { Injectable } from '@angular/core';
@Injectable()
export class UtilService {
deleteData() {
localStorage.removeItem('token');
}
}
这是我的另一项服务,即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() }
}
这是我使用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();}
}
这是我的错误 enter image description here