... just learning Angular, trying to learn the code and not piss off the
community at the same time....
I have a data service component that is successfully returning a stock
quote. With the code below I can output the results to console.log() with
no issues (no errors in the console) but when I try to post onscreen I'm
getting an error message in the console but not onscreen (ERROR TypeError:
Can not read property 'symbol' of undefined) even though the data is still
present, visible and correct. What I want displayed onscreen is actually
correctly displayed onscreen, just with this error in the console.
*STOCKS.COMPONENT.TS:*
*import { Component } from '@angular/core';*
*import { DataService } from '../../services/data.service';*
*@Component({*
* selector: 'app-stocks',*
* template: `<h1>Hello from Stocks Component</h1>*
* Todays closing price for {{ stock.symbol }} is {{stock.close}}. `*
*})*
*export class StocksComponent {*
* stock:any[];*
* constructor(public dataService:DataService)*
* {*
* this.dataService.getStocks().subscribe(stock => {*
* //console.log(stock);*
* this.stock = stock;*
* });*
* }*
*}*
... so obviously the issue is with my template code and how I'm referring
to the specific value(s) in the stock array. Can anyone set me straight on
the correct syntax to display array results onscreen without getting the
console error?
Thanks in advance,
Rich
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.