实现Angular 4 Dropdown会导致出现错误消息

时间:2017-10-12 07:41:06

标签: javascript angular typescript

我正在尝试实施ng4-material-dropdown

我做的步骤:

1)我已安装:

  

npm install ng4-material-dropdown --save   2)安装完成后,导入指令:

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { routing } from './app.routing';
import { AgmCoreModule } from '@agm/core';
import { customHttpProvider } from './_helpers/index';
import { AlertComponent } from './_directives/index';
import { AuthGuard } from './_guards/index';
import { AlertService, AuthenticationService, UserService } from './_services/index';
import { HomeComponent } from './home/index';
import { LoginComponent } from './login/index';
import { RegisterComponent } from './register/index';
import { HeaderComponent } from './header/header.component';
import { DashboardComponent } from './dashboard/index';
import { Ng4DropdownModule } from 'ng4-material-dropdown';

@NgModule({
imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    AgmCoreModule.forRoot({
    apiKey: 'eer'
    }),
    Ng4DropdownModule,
    routing
],
declarations: [
    AppComponent,
    AlertComponent,
    HomeComponent,
    LoginComponent,
    RegisterComponent,
    HeaderComponent,
    DashboardComponent
 ],
 providers: [
    customHttpProvider,
    AuthGuard,
    AlertService,
    AuthenticationService,
    UserService
 ],
 bootstrap: [AppComponent]
 })

导出类AppModule {}

3)我在dashboard.component.html文件中使用了它:

dashboard.component.html

<app-header></app-header>
<div class="container">
<ng4-dropdown>
<ng4-dropdown-menu>
    <ng4-menu-item *ngFor="let item of items">
      {{ item }}
    </ng4-menu-item>
  </ng4-dropdown-menu>
</ng4-dropdown>

<agm-map [latitude]="lat" [longitude]="lng">
  <agm-marker 
          [latitude]="lat"
          [longitude]="lng"></agm-marker>
</agm-map>
</div>

dashboard.component.ts

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AlertService, AuthenticationService } from '../_services/index';

@Component({
   moduleId: module.id,
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements OnInit {
 title: string = 'My first AGM project';  
  lat: number = 51.673858;
  lng: number = 7.815982;
  ngOnInit() {
  }

 pages =['abc','bca','pqr'];


  constructor() {
   }
}

当我尝试它时,我收到以下错误:

TypeError: Cannot read property 'setGlobalVar' of null
    at _createNgProbe (ng4-dropdown.bundle.js:6944)
    at eval (module.ngfactory.js? [sm]:1)
    at _callFactory (core.es5.js:9574)
    at _createProviderInstance$1 (core.es5.js:9503)
    at initNgModule (core.es5.js:9454)
    at new NgModuleRef_ (core.es5.js:10568)
    at createNgModuleRef (core.es5.js:10552)
    at Object.debugCreateNgModuleRef [as createNgModuleRef] (core.es5.js:12861)
    at NgModuleFactory_.webpackJsonp.../../../core/@angular/core.es5.js.NgModuleFactory_.create (core.es5.js:13856)
    at core.es5.js:4497

你能告诉我这里做错了什么,以及这个错误意味着什么?

2 个答案:

答案 0 :(得分:0)

我认为这个套餐已经过时了。上次提交是7个月前。我建议您使用其他包含更多支持的包。

答案 1 :(得分:0)

模块未初始化。你可以在node_module中看到ng4-dropdown.bundle.js并在这个函数中搜索函数名'initDomAdapter'.add调试器,它不会运行。