我制作了一个路由服务,并想将它注入到我的导航组件中。但当我调用其中的一个方法时,它会抛出TypeError: routingService.getRequestedPage不是一个函数
。昨天我遇到了一个非常类似的问题,不幸的是我忘记了如何解决它。我是通过终端生成服务的。
src/app/nav/nav.component.ts
构造函数:
constructor(private templateService: TemplateService, private routingService: RoutingService) {
this.getTemplates();
if (this.routingService.getRequestedPage() === 'home') {
this.showHome();
}
}
src/app/nav/nav.component.ts
的导入:
import {RoutingService} from '../shared/routing.service';
src/app/shared/routing.service.ts
:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class RoutingService {
private requestedPage: string;
constructor() {
this.requestedPage = 'home';
}
requestPage(page: string) {
this.requestedPage = page;
}
getRequestedPage() {
return this.requestedPage;
}
}
RoutingService
的导入是什么样子的? - ViqMontana