2017-07-26 51 views
0

首先我在角框架初學者無法解析AnalysisComponent所有參數:??([目標對象],[

當我加入項目的服務,然後我得到這個錯誤

。 。

Error: Can't resolve all parameters for AnalysisComponent: ([object Object], ?, ?, [object Object], [object Object], [object Object], [object Object], [object Object]).

角4.0.0

我無法理解如何解決它

calendar.component.ts:

import { Component, ChangeDetectionStrategy, Inject, ViewChild, TemplateRef, OnInit } from '@angular/core'; 
    import { DOCUMENT } from '@angular/platform-browser'; 
    import { Router } from '@angular/router'; 
    import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; 
    import { InternService } from '../intern.service'; 
    import { AuthService } from '../../user/auth.service'; 
    import { ToastrService } from '../../common/toastr.service'; 
    import { IIntern } from '../intern'; 

    import { 
     startOfDay, 
     endOfDay, 
     subDays, 
     addDays, 
     endOfMonth, 
     isSameDay, 
     isSameMonth, 
     addHours 
    } from 'date-fns'; 

    import { Subject } from 'rxjs/Subject'; 

    import { 
     CalendarEvent, 
     CalendarEventAction, 
     CalendarEventTimesChangedEvent 
    } from 'angular-calendar'; 

    const colors: any = { 
     red: { 
     primary: '#ad2121', 
     secondary: '#FAE3E3' 
     }, 
     blue: { 
     primary: '#1e90ff', 
     secondary: '#D1E8FF' 
     }, 
     yellow: { 
     primary: '#e3bc08', 
     secondary: '#FDF1BA' 
     } 
    }; 

    export interface IEvent { 
     start: Date, 
     end: Date, 
     title: string, 
     color: { primary: string, secondary: string }, 
     actions: CalendarEventAction[] 
    } 

    @Component({ 
     selector: 'app-fullcalendar', 
     changeDetection: ChangeDetectionStrategy.OnPush, 
     templateUrl: './calendar.component.html', 
     styleUrls: ['./calendar.component.scss'] 
    }) 
    export class AnalysisComponent implements OnInit { 

     @ViewChild('modalContent') modalContent: TemplateRef<any>; 

     view = 'month'; 

     viewDate: Date = new Date(); 

     modalData: { 
     action: string, 
     event: CalendarEvent 
     }; 

     actions: CalendarEventAction[] = [{ 
     label: '<i class="editButton"></i>', 
     onClick: ({ event }: { event: CalendarEvent }): void => { 
      this.handleEvent('Edited', event); 
     } 
     }, { 
     label: '<i class="deleteButton"></i>', 
     onClick: ({ event }: { event: CalendarEvent }): void => { 
      this.events = this.events.filter(iEvent => iEvent !== event); 
      this.handleEvent('Deleted', event); 
     } 
     }]; 

     refresh: Subject<any> = new Subject(); 

     events: CalendarEvent[] = []; 

     ngOnInit() { 
     this.internService.getInternsByOption('all') 
      .subscribe(data => { 
      if (data.success === false) { 
       if (data.errcode) { 
       this.authService.logout(); 
       this.router.navigate(['login']); 
       } 
       this.toastr.error(data.message); 
      } else { 
       console.log(data.data); 
      } 
      }); 
     } 

     activeDayIsOpen = true; 

     constructor(private modal: NgbModal, 
     private iintern: IIntern, private ievent: IEvent, 
     private internService: InternService, 
     private toastr: ToastrService, 
     private router: Router, 
     private authService: AuthService, 
     @Inject(DOCUMENT) doc: any) { } 

     dayClicked({ date, events }: { date: Date, events: CalendarEvent[] }): void { 

     if (isSameMonth(date, this.viewDate)) { 
      if (
      (isSameDay(this.viewDate, date) && this.activeDayIsOpen === true) || 
      events.length === 0 
     ) { 
      this.activeDayIsOpen = false; 
      } else { 
      this.activeDayIsOpen = true; 
      this.viewDate = date; 
      } 
     } 
     } 

     eventTimesChanged({ event, newStart, newEnd }: CalendarEventTimesChangedEvent): void { 
     event.start = newStart; 
     event.end = newEnd; 
     this.handleEvent('Dropped or resized', event); 
     this.refresh.next(); 
     } 

     handleEvent(action: string, event: CalendarEvent): void { 
     this.modalData = { event, action }; 
     this.modal.open(this.modalContent, { size: 'lg' }); 
     } 

     addEvent(): void { 
     this.events.push({ 
      title: 'New event', 
      start: startOfDay(new Date()), 
      end: endOfDay(new Date()), 
      color: colors.red, 
      draggable: true, 
      resizable: { 
      beforeStart: true, 
      afterEnd: true 
      } 
     }); 
     this.refresh.next(); 
     } 

     eventCreator(eventintern: IIntern) { 
     let a = this.ievent; 
     a.start = eventintern.starteddate; 
     a.end = eventintern.endeddate; 
     a.color = colors.red; 
     a.actions = this.actions; 
     this.events.push(a); 
     } 
    } 

回答

2

你的問題是在這裏:

constructor(private modal: NgbModal, 
    private iintern: IIntern, private ievent: IEvent, 
    private internService: InternService, 
    private toastr: ToastrService, 
    private router: Router, 
    private authService: AuthService, 
    @Inject(DOCUMENT) doc: any) { } 

刪除從你的構造private iintern: IIntern, private ievent: IEvent@Inject(DOCUMENT) doc: any下,我不能完全肯定doc正在使用什麼?

我從移除的物品中看到的唯一一條線是private ievent: IEvent。如果需要這些用作varibales,你將它們添加到您的組件的頂部像這樣:

export class AnalysisComponent implements OnInit { 
    public event: IEvent; 
    public intern: IIntern; 
    public doc: DOCUMENT; 

你的構造應該是這樣的:

constructor(private modal: NgbModal, 
    private internService: InternService, 
    private toastr: ToastrService, 
    private router: Router, 
    private authService: AuthService) { } 
+1

我覺得他的問題是接口'私人iintern:IIntern,私人ievent:IEvent,' – yurzui

+0

Sory爲我的spagetti。它還沒有解決同樣的錯誤。 –

+0

@yurzui我在忙着更新我的答案,而你評論:) –

相關問題