title: Get data from subscribe function in local variable angular 6
body: <p>This is my api call using post in my app.service.ts</p>
  
  <pre><code>userinsert(user:User,cart:Cart[])
  {
  
      var databaseinput={user:user,cart:cart};
    return  this.http.post("http://localhost:3000/api/payment",databaseinput);
  
  }
  </code></pre>
  
  <p>and this is my cart.component.ts
  I am using subscribe here to get data like this</p>
  
  <pre><code>export class CartComponent{
      mydata:string;
  myfuncto(){
      this.appservice.userinsert(user,currentcart).subscribe(
        data =&gt; {this.mydata=data// want to do something like this
        },
        error =&gt; { console.log(error); // Error if any
        },
        ()=&gt; {}
  
      )
  console.log(mydata) //it should print the data
  }
  }
  </code></pre>
  
  <p>But it gives me error type object is not assignable to type string ,I used data.json() but no success ,any idea how to do it??</p>