当前位置: 首页 > 知识库问答 >
问题:

如何修复“错误:StaticInjectorError(app module)[NgbDropdown-> changededetorref]”

缪远航
2023-03-14

我正在尝试使用 Angular 创建一个网络应用程序,该项目编译时没有错误。执行时,浏览器显示一个空白页并返回此错误:

错误 错误: 未捕获(在promise中): 错误: 静态注入器错误(应用模块)[NgbDropdown -

StaticInjectorError(平台:核心)[NgbDropdown -

NullIn的错误:没有提供者的变更检测参考!

错误:StaticInjectorError(AppModule)[NgbDropdown-

StaticInjectorError(平台:核心)[NgbDropdown -

NullIn的错误:没有提供者的变更检测参考!

NullInjector.push./node_modules/@角/核/fesm5/core.js.NullInjector.get(core.js: 8896)

在resolveToken(core.js: 9141)

在tryResolveToken(core.js:9085)

StaticInjector.push./node_modules/@角/核/fesm5/core.js.StaticInjector.get(core.js: 8982)

在resolveToken(core.js: 9141)

在tryResolveToken(core.js:9085)

StaticInjector.push./node_modules/@角/核/fesm5/core.js.StaticInjector.get(core.js: 8982)

位于resolveNgModuleDep(core . js:21218)

在NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get(core.js:21907)

在resolveDep(core.js: 22278)

在解析promise(区域.js: 831)

在resolvePromise(zone.js:788)

在区域.js: 892

在ZoneDelegate.push../node _ modules/zone . js/dist/zone . js . zone delegate . invoke task(zone . js:423)

在Object.on调用任务(core.js: 17290)

位于ZoneDelegate.push../node_modules/zone。js/dist/zone.js.ZoneDelegate.invokeTask(zone.js:422)

位于Zone.push../node_modules/Zone。js/dist/zone.js.zone.runTask(zone.js:195)

在排水微任务队列(区域.js: 601)

那是我的app.module.ts:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { ToastrModule } from 'ngx-toastr';

import { AppRoutingModule } from './app-routing.module';
import { ComponentsModule } from './components/components.module';

import { AppComponent } from './app.component';

import { AdminLayoutComponent } from './layouts/admin-layout/admin-layout.component';

@NgModule({
  imports: [
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    ComponentsModule,
    RouterModule,
    AppRoutingModule,
    NgbModule,
    ToastrModule.forRoot()
  ],
  declarations: [
    AppComponent,
    AdminLayoutComponent

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

这是我的包。json:

{
  "name": "test-project",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.2.0",
    "@angular/common": "~7.2.0",
    "@angular/compiler": "~7.2.0",
    "@angular/core": "~7.2.0",
    "@angular/forms": "~7.2.0",
    "@angular/platform-browser": "~7.2.0",
    "@angular/platform-browser-dynamic": "~7.2.0",
    "@angular/router": "~7.2.0",
    "core-js": "^2.5.4",
    "rxjs": "~6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.0",
    "@angular/cli": "~7.3.8",
    "@angular/compiler-cli": "~7.2.0",
    "@angular/language-service": "~7.2.0",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.2"
  }
}

我的app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'testProject';
}

和管理布局.组件. ts

import { filter } from 'rxjs/operators';
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Location, LocationStrategy, PathLocationStrategy, PopStateEvent } from '@angular/common';

import { NavbarComponent } from '../../components/navbar/navbar.component';
import { Router, NavigationEnd, NavigationStart } from '@angular/router';
import { Subscription, Observable } from 'rxjs';
import PerfectScrollbar from 'perfect-scrollbar';

@Component({
  selector: 'app-admin-layout',
  templateUrl: './admin-layout.component.html',
  styleUrls: ['./admin-layout.component.css']
})
export class AdminLayoutComponent implements OnInit {
  private _router: Subscription;
  private lastPoppedUrl: string;
  private yScrollStack: number[] = [];

  constructor(public location: Location, private router: Router) { }

  ngOnInit() {
    const isWindows = navigator.platform.indexOf('Win') > -1 ? true : false;

    if (isWindows && !document.getElementsByTagName('body')[0].classList.contains('sidebar-mini')) {
      // if we are on windows OS we activate the perfectScrollbar function

      document.getElementsByTagName('body')[0].classList.add('perfect-scrollbar-on');
    } else {
      document.getElementsByTagName('body')[0].classList.remove('perfect-scrollbar-off');
    }
    const elemMainPanel = <HTMLElement>document.querySelector('.main-panel');
    const elemSidebar = <HTMLElement>document.querySelector('.sidebar .sidebar-wrapper');

    this.location.subscribe((ev: PopStateEvent) => {
      this.lastPoppedUrl = ev.url;
    });
    this.router.events.subscribe((event: any) => {
      if (event instanceof NavigationStart) {
        if (event.url != this.lastPoppedUrl)
          this.yScrollStack.push(window.scrollY);
      } else if (event instanceof NavigationEnd) {
        if (event.url == this.lastPoppedUrl) {
          this.lastPoppedUrl = undefined;
          window.scrollTo(0, this.yScrollStack.pop());
        } else
          window.scrollTo(0, 0);
      }
    });
    this._router = this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
      elemMainPanel.scrollTop = 0;
      elemSidebar.scrollTop = 0;
    });
    if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
      let ps = new PerfectScrollbar(elemMainPanel);
      ps = new PerfectScrollbar(elemSidebar);
    }
  }
  ngAfterViewInit() {
    this.runOnRouteChange();
  }
  isMaps(path) {
    var titlee = this.location.prepareExternalUrl(this.location.path());
    titlee = titlee.slice(1);
    if (path == titlee) {
      return false;
    }
    else {
      return true;
    }
  }
  runOnRouteChange(): void {
    if (window.matchMedia(`(min-width: 960px)`).matches && !this.isMac()) {
      const elemMainPanel = <HTMLElement>document.querySelector('.main-panel');
      const ps = new PerfectScrollbar(elemMainPanel);
      ps.update();
    }
  }
  isMac(): boolean {
    let bool = false;
    if (navigator.platform.toUpperCase().indexOf('MAC') >= 0 || navigator.platform.toUpperCase().indexOf('IPAD') >= 0) {
      bool = true;
    }
    return bool;
  }

}

共有1个答案

梁丘兴腾
2023-03-14

NullInjectorError:ChangeDetectorRef没有提供程序!

告诉您需要在组件中导入 changeDetectorRef:

import { ChangeDetectorRef } from '@angular/core'

然后在构造函数中:

constructor(private changeDetectorRef: ChangeDetectorRef){}

然后,您可以在组件中使用它,如下所示:< code > this.changeDetectorRef...

 类似资料:
  • ProjectAAA.obj:错误LNK2001:未解析的外部符号" public:_ this call X::class event::class event(unsigned int)"(??0类事件@X@@QAE@I@Z) 我已经定义了不知道如何修复这个LINK错误。 欢迎提出任何建议。 谢谢你 更多信息: 1. 现在我已经完全隔离了错误: 1.

  • 问题内容: 向MySQL发出命令时,出现错误#1064“语法错误”。 这是什么意思? 我该如何解决? 问题答案: 错误#1064表示MySQL无法理解您的命令。要解决这个问题: 阅读错误消息。 它 准确地 告诉您MySQL 在命令中哪里 混淆了。 检查您的命令。 如果您使用的编程语言来创建你的命令,使用,或同等学历,以显示 完整的命令 ,所以你可以看到它。 检查手册。 通过对MySQL的什么比较

  • 尝试了许多解决办法,但都无济于事 参考:在当前主题中找不到样式“协调器LayoutStyle” 但没有帮助 底部App Bar材质设计 应用程序条:底部材质设计

  • 我正在编程一个需要Hibernate技术的项目。我得到了堆栈痕迹,但我不知道如何修复它。有什么需要帮忙的吗? 这是我的堆栈跟踪,我得到了这两个错误: SLF4J:slf4j-api 1.6.x(或更高版本)与此绑定不兼容。SLF4J:您的绑定是1.5.5或更早版本。SLF4J:将绑定升级到1.6.x版本。或2.0.x 导入org.hibernate.hibernateException;导入org