Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Angular Basics Services in Angular Connecting a Service and Component

Courtney Hoskins
Courtney Hoskins
6,898 Points

backend.ts errors

I am getting the following for all of the photos:

ERROR in ./src/app/backend.ts Module not found: Error: Can't resolve '../../photos/Burning-sundown-behind-trees.jpg' in '/Users/captainpj/Documents/workspace/angular-redesign/src/app' @ ./src/app/backend.ts 11:23-79 @ ./src/app/app.module.ts @ ./src/main.ts @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/main.ts

With the next two errors loading after: ERROR in [at-loader] ./src/app/entries/shared/entry.service.ts:14:8 TS2339: Property 'toPromise' does not exist on type 'Observable<Response>'.

ERROR in [at-loader] ./src/app/entries/shared/entry.service.ts:15:13 TS7006: Parameter 'response' implicitly has an 'any' type.

I also get the following when I try to install angular-in-memory-web-api, which may or may not be related

├── angular-in-memory-web-api@0.2.4 ├── UNMET PEER DEPENDENCY rxjs@5.2.0 └── UNMET PEER DEPENDENCY zone.js@0.7.8

I've been working at this for a while. Any ideas? backend.ts was copied from the instructor files. My entry.service.ts looks like this:

import { Entry } from './entry.model'; import { Injectable } from '@angular/core'; import { Http } from '@angular/http';

@Injectable() export class EntryService {

constructor(private http: Http) {

}

getEntries(): Promise<Entry[]> {
    return this.http.get('/app/entries')
                    .toPromise()
                    .then(response => response.json().data as Entry[]);
}

}

Many thanks in advance!

2 Answers

Can you share your workspace? Also, did you copy the "photos" directory into your local version? Not having a local copy of the photos can make your app blow.

Courtney Hoskins
Courtney Hoskins
6,898 Points

Not having a local copy of photos was definitely causing the first error! The second two seemed to stem from the fact that I needed to add:

import 'rxjs/add/operator/toPromise';

to my main.ts file to get the toPromise working properly for some reason. I think there is some weird wire-crossing going on with node package versions.