Thank you for your help!
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
On Monday, November 6, 2017 at 6:13:10 PM UTC-7, Rich Leach wrote:
>
> Hi
>
> I'm trying to build a string from a form that I will ultimately pass as a
> url for a service call.
>
> I have a hard coded string, something like '
> https://api.iextrading.com/1.0/stock/IBM/quote'
>
> ... where "IBM" will be dynamically updated with the user entered value.
>
> So in my html template I have
> <input type="text" class="form-control" [(ngModel)]="tickersymbol">
> <div>
> https://api.iextrading.com/1.0/stock/{{tickersymbol}}/quote
> </div>
>
> ...which outputs my desired string to the screen.
>
> Like I said, n00b question, but how/where would I capture the value from
> the form field and then pass it to my service?
>
> 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.