简体   繁体   English

Angular2-无效的NgModule提供程序,仅允许提供程序和类型的实例

[英]Angular2 - Invalid provider for the NgModule only instances of Provider and Type are allowed

I got this traceback and I can't replicate this error. 我得到了此追溯,并且无法复制此错误。

vendor.bundle.js:25942 
Uncaught Error: Invalid provider for the NgModule 'NbSharedModule' 
- only instances of Provider and Type are allowed, 
got: [[object Object], MaterialDashboardProService, VehicleTypesService, ?undefined?, ...]

Here is my NbSharedModule 这是我的NbSharedModule

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import {MaterialModule} from '@angular/material';

import { AdminFormComponent } from './admin-form/admin-form.component';
import {
  MaterialDashboardProService,
  VehicleTypesService,
  LocationsService,
  VehiclesService,
  BookingsService,
  NotificationService,
  UsersService
} from './services';
import { OrganisationFormComponent } from './organisation-form/organisation-form.component';
import {
  MdpActivatorDirective,
  MdpBootstrapSelectDirective,
  MdpDatetimePickerDirective,
  MdpTagsinputDirective
} from './directives';
import { ChunkPipe } from './pipes/chunk.pipe';
import { VehicleTypesChooserComponent } from './vehicle-types-chooser/vehicle-types-chooser.component';
import { VehicleCardComponent } from './vehicle-card/vehicle-card.component';
import { LoaderComponent } from './loader/loader.component';
import { NotificationComponent } from './notification/notification.component';
import { TagsinputComponent } from './tagsinput/tagsinput.component';
import { VehicleFormComponent } from './vehicle-form/vehicle-form.component';
import { DeletePopupComponent } from './delete-popup/delete-popup.component';

@NgModule({
  declarations: [
    OrganisationFormComponent,
    AdminFormComponent,
    MdpActivatorDirective,
    MdpDatetimePickerDirective,
    MdpBootstrapSelectDirective,
    MdpTagsinputDirective,
    ChunkPipe,
    VehicleTypesChooserComponent,
    VehicleCardComponent,
    LoaderComponent,
    NotificationComponent,
    TagsinputComponent,
    VehicleFormComponent,
    DeletePopupComponent
  ],
  imports: [
    CommonModule,
    ReactiveFormsModule,
    FormsModule,
    MaterialModule.forRoot()
  ],
  providers: [
    {provide: 'windowObject', useValue: window},
    MaterialDashboardProService,
    VehicleTypesService,
    LocationsService,
    VehiclesService,
    BookingsService,
    NotificationService,
    UsersService
  ],
  exports: [
    OrganisationFormComponent,
    AdminFormComponent,
    MdpActivatorDirective,
    MdpDatetimePickerDirective,
    MdpBootstrapSelectDirective,
    MdpTagsinputDirective,
    ChunkPipe,
    VehicleTypesChooserComponent,
    VehicleCardComponent,
    LoaderComponent,
    NotificationComponent,
    TagsinputComponent,
    VehicleFormComponent,
    DeletePopupComponent
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class NbSharedModule { }

package.json

{
  "name": "foo-app",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.4.0",
    "@angular/compiler": "2.4.0",
    "@angular/core": "2.4.0",
    "@angular/forms": "2.4.0",
    "@angular/http": "2.4.0",
    "@angular/material": "^2.0.0-beta.1",
    "@angular/platform-browser": "2.4.0",
    "@angular/platform-browser-dynamic": "2.4.0",
    "@angular/router": "3.2.3",
    "@angular2-material/slide-toggle": "^2.0.0-alpha.8-2",
    "@types/jquery.datatables": "^1.10.34",
    "angular2-fullcalendar": "^1.1.1",
    "angular2-moment": "^1.0.0",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@angular/compiler-cli": "2.4.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "^1.0.0-beta.24",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-phantomjs-launcher": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "^4.0.2",
    "typescript": "~2.0.3",
    "webdriver-manager": "10.2.5"
  }
}

For me, I have included two export statements for same service in service's index.ts file. 对我来说,我在服务的index.ts文件中包含了两个针对同一服务的导出语句。 Finally it works after removing one. 最后,它删除一个后,它可以工作。

services/index.ts

export * from './material-dashboard-pro.service';
export * from './vehicle-types.service';
export * from './locations.service';
export * from './vehicles.service';
export * from './locations.service'; // duplicated, remove this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 添加提供程序@NgModule时,Angular2“没有服务提供程序!”错误 - Angular2 “No provider for Service!” error when provider is added @NgModule 在 Angular 2 中测试服务时 NgModule 'DynamicTestModule' 的提供程序无效 - Invalid provider for the NgModule 'DynamicTestModule' when testing a service in Angular 2 Angular2 - 没有ExceptionHandler的提供者 - Angular2 - No provider for ExceptionHandler Angular2 - 没有LoggedInGuard的提供者 - Angular2 - No provider for LoggedInGuard Angular2-将服务注入服务时出现无效的提供程序错误 - Angular2 - Invalid provider error when injecting service into service Angular2:例外:没有 Angulartics2GoogleAnalytics 的提供者 - Angular2 : EXCEPTION: No provider for Angulartics2GoogleAnalytics Angular2 测试用例显示 NgControl 没有提供者 - Angular2 testcase shows No provider for NgControl Angular2:提供模型服务-“没有模型提供者” - Angular2: Service with Model - “no provider for model” Electron app中的Angular2错误:没有PlatformRef的提供者 - Angular2 error in Electron app: No Provider for PlatformRef Angular2:在 Angular2 中使用 Jquery:错误:没有 Token jQuery 的提供者 - Angular2 : Using Jquery in Angular2 : Error: No provider for Token jQuery
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM