0

I am doing something wrong with my simple service but I can not figure it out.

app.component.ts

import { MeetingService } from '../../shared/services/meeting.service';

@Component({
  viewProviders: [MeetingService],
})

meetingService.ts

@Injectable();

export class MeetingService {

  constructor(private http: Http) {}

  getList() {
    return this.http.get('../fake-data/meetingList.json')
      .map(response => response.json());
  }
}

meetingList.component.ts

import { MeetingService } from '../../shared/services/meeting.service';

@Component({
  viewProviders: [HTTP_PROVIDERS, MeetingService],
})

export class MeetingListComponent {
  private meetingList: any;

  constructor(private meetingService: MeetingService) {}

  getList() {
    this.meetingService.getList().subscribe(
      data => { this.meetingList = data; },
      err  => console.error(err),
      ()   => console.log('done loading meeting list')
    );
  }

  ngOnInit() {
    this.getList();
  }
}

Error

EXCEPTION: Cannot resolve all parameters for 'MeetingService'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'MeetingService' is decorated with Injectable.

Can somebody take a look at it? Thank you.

0

2 Answers 2

2

Just remove ; after @Injectable()

@Injectable()
export class MeetingService {

  constructor(private http: Http) {}

  getList() {
    return this.http.get('../fake-data/meetingList.json')
      .map(response => response.json());
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

; means statement finished.
0

You don't show your bootstrap code - did you add Http to your application providers during bootstrap, e.g.,

bootstrap(App, [HTTP_PROVIDERS])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.