0
我得到了這個追蹤,我無法複製此錯誤。Angular2 - 允許提供者和類型的NgModule唯一實例的無效提供者
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?, ...]
下面是在服務的index.ts
文件相同的服務我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"
}
}
出於某種原因'LocationService'是不確定的。看起來你正在使用桶(index.ts)作爲服務。有時用通配符重新導出可能導致此問題。有幾件事我見過會導致這種情況(通常是使用webpack)。 –
所以最好直接從文件導入服務,而不是index.ts, –
昨天工作正常。今天只有我在除了主人以外的所有分支中都有這個錯誤。這是節點包的東西嗎?我嘗試刪除節點模塊文件夾並重新安裝軟件包。 –