user1034912
user1034912

Reputation: 2257

Angular 2/4: How to call Web Apis via Http Post with parameters?

I'm a newbie with regards to Angular. I've looked at several places and most of the examples are extremely complicated. Is there something simple which I can start from? Something that calls a web api which accepts 2 parameter and returns an object

[HttpPost("GetHomePageData")]
        public HomePageData GetHomePageData(int P1, int P2)
        {
            //
        }

public class HomePageData
    {
        public int AddressCount { get; set; }        
    }

Upvotes: 0

Views: 291

Answers (1)

axl-code
axl-code

Reputation: 2274

In Angular's official documentation you can see examples like this:

@Component(...)
export class MyComponent implements OnInit {

  results: string[];

  // Inject HttpClient into your component or service.
  constructor(private http: HttpClient) {}

  ngOnInit(): void {
    // Make the HTTP request:
    this.http.get('/api/items').subscribe(data => {
      // Read the result field from the JSON response.
      this.results = data['results'];
    });
  }
} 

Upvotes: 1

Related Questions