export class MyComponent {
tickersymbol:string;
// later in the code...
getQuote() {
this.myService.getQuote(this.tickerSymbol).subscribe(....);
}
}
In the associated component you just need something like :
@Input() tikersymbol: string;
As you use two way binding the value will be updated when the user enter a value.
Here is the angular doc : https://angular.io/guide/template-syntax#two-way-binding---
@Component({
selector: 'my-cmp',
...
})
export class MyCmp {
@Input() tickerSymbol:string;
}
// another component which users MyCmp
@Component({
selector: 'parent-cmp',
template: `
<p>This is the parent template using MyCmp as child component.
It gives it "tickerSymbol" as input.
</p>
<my-cmp [tickerSymbol]="'IBM'"></my-cmp>
I think the larger question is, how do I actually parse, and pass, the string (that will represent the actual URL to my web service) from my .html form and into my .ts component (to ultimately inject into the service)?
I've been targeting the strategy of trying to combine the 2 strings (tickersymbolfront is always static, tickersymbolback is where the form value from the user gets appended) and then pass that combined value to the method (in the service). I get the feeling I'm doing something silly where I'm not able to join the strings correctly and/or incorrectly passing them to the method....
SNIPPETS:
.HTML
<button class="btn btn-primary" (click)="onGetStock()">Get Stock</button>
<input type="text" class="form-control" [(ngModel)]="tickersymbol">
.TS
...
export class AppComponent {
tickersymbolfront:string = 'https://api.iextrading.com/1.0/stock/';
tickersymbolback:string = '{{tickersymbol}}'&&'/quote';
apicall={{tickersymbolfront}}+{{tickersymbolback}};
...
onGetStock(apicall) {
this.serverService.getStock()
.subscribe(
(data: any[]) => console.log(data),
(error) => console.log(error)
);
}
SERVICE.TS
...
getStock() {
return this.http.get('https://api.iextrading.com/1.0/stock/TTD/quote') //this will get updated with the parsed string from the user submitted value
.map(
(response:Response) => {
const data = response.json();
return data;
}
);
}
Again, thanks for your help.
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 angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to a topic in the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/nmbleJuxqvI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
LOL... you would think this would be something easy....{{data[0].companyName}} is not working, nothing gets returned (no errors either).I've included the returned json below (copied directly from the console). In my service call I'm actually calling "... response.json()" so I'm not sure why this isn't rendering to the screen. I even tried<div *ngFor="let d of data">QUOTE RETURNED: {{data[0].companyName}}</div>... no dice. Any ideas?