Lorin S (45) [Avatar] Offline
#1
If implemented as read in the example, line app.component.ts:15 reads:

this.stocks = stocks.json();

This results in the following error in Chrome:

EXCEPTION: stocks.json is not a function


Alternatively, at least in Chrome, the following simple assignment seems to suffice:

this.stocks = stocks;
jeremy.wilken (201) [Avatar] Offline
#2
At what point exactly are you running this, and what code listing is this from?
Lorin S (45) [Avatar] Offline
#3
This was copied and pasted from Listing 2.9... Ran in due course of running through the demo.
jeremy.wilken (201) [Avatar] Offline
#4
I don't see why this is happening, but can you check you have the service correct? Can you check your code against the code in GitHub and see if there is anything different with your version?

https://github.com/angular-in-action/stocks
476453 (3) [Avatar] Offline
#5
I confirm the error. Currently, I'm at the end of "2.5 Creating your first component". Build fails with: "/stocks/src/app/app.component.ts (15,2smilie: Property 'json' does not exist on type 'StockInterface[]'.". When I remove the .json call, everything builds and works fine.
Geoff Fox (2) [Avatar] Offline
#6
error.png
[ 33 KB ]
I have run into the same error! Please provide a working complete solution.
Thanks,
Geoff

Just downloaded your code solution. It's working and I can now check out my code.
Thank you for providing a working solution. smilie
Geoff
jeremy.wilken (201) [Avatar] Offline
#7
This looks like an outdated version of the code, which might mean checking you have the latest MEAP or that the final version of the book will be fixed (and match what is on github).
Geoff Fox (2) [Avatar] Offline
#8
Hi Jeremy,
Got it all working and learnt a lot!
Nice book, looking forward to the final version.

Your github code solution helped. smilie

Thanks,
Geoff Fox

PS there are some inconsistencies in the MEAP book:

ng generate component components/summary
gives a selector <app-summary></app-summary>
the book shows <summary></summary>

ng generate component components/summary --prefix=false

or change the .angular-cli.json from the default prefix "app"

would fix it.
431294 (1) [Avatar] Offline
#9
app.component.ts fails to run - book still inconsistent
As far as I see the book version is still outdated. The github code of app.component.ts does not contain references to json, but Chapter 2 (both in the latest version I have as well as in the live book, listing 2.9) still refer to json.

Not using the github but trying to start from ng new all the way as explained in chapter 2 does not work at the moment.
welkie (21) [Avatar] Offline
#10
Can confirm that I experienced this while reading Chapter 2 of V12 today. Removing the ".json()" worked. Seems the new HttpClient returns it as JSON automatically.
Julitogtu (1) [Avatar] Offline
#11
Yes, removing
.tojson()
the code works, also, look in github (https://github.com/angular-in-action/stocks/commit/613c82b84ad96d54523fcc63b038066e52b3d889#diff-5c26d2c8f8838f32ace87fdecd6344ea) the changes of the component and confirm that the before version of the code does not use the
.tojson()
jeremy.wilken (201) [Avatar] Offline
#12
Getting this fixed for good in the proofs, thanks for pointing it out.