1

The following URL works - I've tested it in Chrome and Postman.

https://localhost:44319/api/portfolio

Here is my invocation in my typescript module. I have a breakpoint on this line and I see this line execute. (If you think a broader view of my code is relevant to the question, please let me know and I will post it.)

this.http.get<Portfolio[]>('https://localhost:44319/api/portfolio');

The line executes, but my web API method doesn't get called. I know it's not getting called because I am running my project in debug mode and I have breakpoints in my typescript method and in the first line of my web API method. I see the breakpoint being hit within the typescript executing on the client side, but the breakpoint within my server side web API method doesn't get hit.

(Although, as I mentioned, if I execute that exact URL from Chrome or Postman the server-side breakpoint hits.)

What am I doing wrong? Thanks!

1
  • How does the scoring work? Three people marked the answer to this question as useful but overall this gets marked as -1? Commented Nov 10, 2019 at 15:53

1 Answer 1

3

You should do:

this.http.get<Portfolio[]>('https://localhost:44319/api/portfolio').subscribe(v
 => { this.Portfolios = r; });

or

this.Portfolios = await this.http.get<Portfolio[]>('https://localhost:44319/api/portfolio').toPromise();
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks! How do I assign the functional return of that API call to the array of Portfolio objects? Defined a a class member variable: public Portfolios: Portfolio[] ;
this.Portfolios[] = await this.http.get('localhost:44319/api/portfolio').toPromise(); This doesn't work for me I get an error becasue it doesn;t want to assign an 'object' to my array of Portfolios. Thanks!
just remove the brackets
When I change this to this.Portfolios = await this.http.get('localhost:44319/api/portfolio').toPromise(); I get the following syntax error: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? Type 'Object' is missing the following properties from type 'Portfolio[]': length, pop, push, concat and 26 more.
Sorry, I don't understand. Can you show me? Thanks!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.