title: Angular 2 + Web API - Post data is not working
body: <p>I am working two projects linked with each other e.g A and B.</p>
  
  <p>In Project A - I've implemented entity framework to fetch data from database.</p>
  
  <p>In Project B - I've implemented Angular 2, fetching data from project A and display it on screen (client).</p>
  
  <p>Both projects are connected with API. Project B's API is calling Project A's API to fetch data from database and displaying to screen(client). to fetch data '<strong>GET</strong>' request is working fine.</p>
  
  <p>Issue : When user filling a form and posting data, '<strong>POST</strong>' method is not working. If I implement same [HttpPost] Method in Project B, then it is working, but I want to post data to Project B's Method.</p>
  
  <p>To understand more easily, I've tried to implement this situation graphically below:(highlighted <em>red</em> part is not working)</p>
  
  <p><a href="https://i.stack.imgur.com/1VSfM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1VSfM.jpg" alt="enter image description here"></a></p>
  
  <p>Posting Data with Angular 2 is working fine as below:</p>
  
  <pre><code>return this.http
          .post(projectAUrl, JSON.stringify({ stateName: stateName }), { headers: this.headers })
          .toPromise()
          .then(res =&gt; res.json().data as AnalyticsState)
  </code></pre>
  
  <p>[HttpPost] Method in Project A's controller is implemented below:</p>
  
  <pre><code>[Route("api/States")]
  [HttpPost]
  public IHttpActionResult PostSaveState([FromBody]string stateName)
  {
      return null;
  }
  </code></pre>
  
  <p>After submitting form, this method is not triggering (tried by putting breakpoint) in Project A, same method is working if I implement in Project B.</p>
  
  <p>Do I have to do something with both project's API to posting data or I'm missing something silly point to achieve posting data into database? New to dotNet core and angular 2, tries to understand project flow.</p>
  
  <p><strong>Note</strong> : I do not want to implement Entity framework in Project B. Project flow should be same as in attached image. </p>
  
  <p>So far I tried many things, but no luck, few links are :</p>
  
  <p><a href="https://stackoverflow.com/questions/34560017/httpclient-call-to-webapi-to-post-data-not-working">httpclient call to webapi to post data not working</a></p>
  
  <p><a href="https://stackoverflow.com/questions/27327830/net-mvc-4-webapi-post-not-working">.NET MVC 4 WebAPI POST not working</a></p>
  
  <p><a href="https://angular.io/docs/ts/latest/tutorial/toh-pt6.html" rel="nofollow noreferrer">https://angular.io/docs/ts/latest/tutorial/toh-pt6.html</a></p>
  
  <p><strong>Working</strong> :  Below Angular function for fetching data from Project A is working fine.</p>
  
  <pre><code> getStates() {
  
      let ProjectAUrl = 'http://localhost:9043/api/GetStates';
  
      return this.http.get(ProjectAUrl )
          .map(res=&gt;res.json()
          .subscribe(States =&gt; this.States = States);
  }
  </code></pre>
  
  <p><strong>Not Working</strong> : When user submitting form, I'm calling below angular function. In below function, if I use ProjectBUrl, control is going into Project B's controller method (Which I don't want). But If I use ProjectAUrl, control is not going to Project A's controller.</p>
  
  <pre><code>SaveState(stateName: string): Promise&lt;State&gt; {
  
      let ProjectAUrl = 'http://localhost:9043/api/States?stateName='+stateName+'';
      let ProjectBUrl = 'api/States?stateName='+stateName+'';
  
      return this.http
          .post(ProjectAUrl , JSON.stringify({ stateName: stateName }), { headers: this.headers })
          .toPromise()
          .then(res =&gt; res.json().data as State)
          .catch(this.handleError);
  }
  </code></pre>
  
  <p>So is there any possibility to call Project A's controller method directly from Project B's angular function? <em>or</em> pass a control from Angular function to Project B's controller and then Call project A's controller from Project B's controller.</p>
  
  <p>Sorry for making it bit confusing and complicated! but any help would be much appreciated.</p>
  
  <p>Any idea how to post data through API in Angular 2?</p>