The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

justinc (16) [Avatar] Offline
#1
CH8, p 288

I have created the data service and reference it in the home-list components. but I receive this error in a browser

home-list.component.ts (29,15): Cannot find name 'foundlocations'.

from this function
private getLocations(): void {
this.loca8r2DataService
.getLocations()
.then(foundlocations, function() {
this.locations = foundLocations;
});
}


I see this error in the console as well.

would it be possible to get these intermediate files posted to github? I could be placing them incorrectly since the book shows snippets but not entire files

simon.holmes (148) [Avatar] Offline
#2
Hi

The data returned from the service - foundlocations In your code - is a parameter of the callback function in the .then when the promise resolves. The function should be like this:

private getLocations(): void { 
  this.loca8r2DataService 
    .getLocations() 
    .then(function(foundlocations) { 
      this.locations = foundLocations; 
    }); 
} 


Which is equivalent to this using arrow functions:

private getLocations(): void { 
  this.loca8r2DataService 
    .getLocations() 
    .then((foundlocations) => { 
      this.locations = foundLocations; 
    }); 
} 


Hope that helps!
Simon
justinc (16) [Avatar] Offline
#3
I changed the code (and I did see the foundLocations in the chapter

I still receive these errors

ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/home-list/home-list.component.ts (30,2smilie: Cannot find name 'foundLocations'.
ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/loca8r2-data.service.ts (2,31): Expression expected.
ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/loca8r2-data.service.ts (2,39): Declaration expected.
ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/loca8r2-data.service.ts (2,40): Unterminated regular expression literal.
ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/loca8r2-data.service.ts (9,3): Multiple constructor implementations are not allowed.
ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/loca8r2-data.service.ts (11,3): Multiple constructor implementations are not allowed.
ERROR in C:/Users/jcalcagni/Documents/software/code/javascript/node/loca8r2/app_public/src/app/home-list/home-list.component.ts (30,2smilie: Cannot find name 'foundLocations'.

I added my data services and home list files if that helps

it almost seems like I had an error / typo but even after I'm saving it's not updating (or my files still have errors). hard to tell without comparing to what "should" be there