не мог понять, почему эта ошибка вызывается
сервисный код:
import { Injectable } from '@angular/core';
import { MatSidenav } from '@angular/material';
@Injectable({
providedIn: 'root'
})
export class SideNavService {
constructor(private matSideNav: MatSidenav) { }
public setSidenav(sidenav: MatSidenav) {
this.matSideNav = sidenav;
}
public open() {
return this.matSideNav.open();
}
public close() {
return this.matSideNav.close();
}
public toggle(): void {
this.matSideNav.toggle();
}
}
и предоставляется в массиве провайдеров в app.module.ts, а также импортирует MatnavBarModule и регистрирует его в массиве импорта......
в компоненте navbar, код файла TS:
import { Component, OnInit, OnDestroy, ChangeDetectorRef, ViewChild } from '@angular/core';
import {MediaMatcher } from '@angular/cdk/layout';
import { MatSidenav } from '@angular/material';
import { SideNavService } from '../services/side-nav.service';
@Component({
selector: 'app-my-orders',
templateUrl: './my-orders.component.html',
styleUrls: ['./my-orders.component.css']
})
export class MyOrdersComponent implements OnInit, OnDestroy {
@ViewChild('snav') public sidenav: MatSidenav;
constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher,private sideNavS:SideNavService) {
// this.mobileQuery = media.matchMedia('(max-width: 500px)');
// this._mobileQueryListener = () => changeDetectorRef.detectChanges();
// this.mobileQuery.addListener(this._mobileQueryListener);
}
ngOnInit(){
this.sideNavS.setSidenav(this.sidenav)
}
получил эту ошибку при загрузке страницы этого компонента:
ОШИБКАОшибка: Uncaught (в обещании): Ошибка: StaticInjectorError (AppModule) [SideNavService -> MatSidenav]:
StaticInjectorError (Платформа: ядро) [SideNavService -> MatSidenav]: NullInjectorError: Нет поставщика для MatSidenav!Ошибка: StaticInjectorError (AppModule) [SideNavService -> MatSidenav]:
StaticInjectorError (Платформа: ядро) [SideNavService -> MatSidenav]: NullInjectorError: Нет поставщика для MatSidenav!в NullInjector.push ../ node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js: 1060) в resolToken (core.js: 1298) в tryResolveToken (core.js: 1242) в StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js: 1139) в resolToken (core.js: 1298) в tryResolveToken (core.js: 1242) в StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js: 1139) в resolNgModuleDep (core.js: 8377) в _createClass (core.js: 8422) в _createProviderInstance (core.js): 8394) в resolPromise (zone.js: 814) в resolPromise (zone.js: 771) в zone.js: 873 в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (zone.js: 421) в Object.onInvokeTask (core.js: 3816) в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (zone.js: 420) в Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js: 188) на канале MicroTaskQueue (zone.js: 595) defaultErrorLogger @ core.js: 1671 push ../ node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js: 1717 next @ core.js: 4320 schedulerFn @ core.js: 3556 push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.SafeSubscriber. tryOrUnsub @ Subscriber.js: 195 push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.SafeSubscriber.next @ Subscriber.js: 133 push ../ node_modules / rxjs / _es/Subscriber.js.Subscriber._next @ Subscriber.js: 77 push ../ node_modules / rxjs / _esm5 / internal / Subscriber.js.Subscriber.next @ Subscriber.js: 54 push ../ node_modules / rxjs / _esm5 / internal/Subject.js.Subject.next @ Subject.js: 47 push ../ node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js: 3540 (анонимный) @ core.js: 3847 push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js: 388 push ../ node_modules / zone.js / dist / zone.js.Zone.run @ zone.js: 138 push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js: 3784 onHandleError @ core.js: 3847 push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.handleError @ zone.js: 392 push ../ node_modules / zone.js / dist / zone.js.Zone.runGuarded @ zone.js: 154 _loop_1 @ zone.js: 677 api.microtaskDrainDone @ zone.js: 686dumpMicroTaskQueue @ zone.js: 602 Promise.then (async) scheduleMicroTask @ zone.js: 578 push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.scheduleTask @ zone.js: 410 push ../ node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js: 232 push ../ node_modules / zone.js / dist / zone.js.Zone.scheduleMicroTask @ zone.js: 252 scheduleResolveOrReject @ zone.js: 862 ZoneAwarePromise.then @ zone.js: 962 push ../ node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModule @ core.js: 4354 ./src/main.ts @ main.ts: 11__webpack_require @ bootstrap: 76 0 @ main.ts: 12 webpack_require @ bootstrap: 76 checkDeferredModules @ bootstrap: 43 webpackJsonpCallback @ bootstrap: 30 (анонимно) @ main.js: 1