Function return value in object t and value stored in __zone_symbol__value:

in following code, I want to return the value but it returns an object:

code :

this.count = count(post.id);
 
console.log(this.count);

.
.
.


count(id,url){

    return new Promise(resolve =>
      this.http.get(url)
        .map(res => res.json())
        .subscribe(data => {
          console.log(data.count);// it shows 3 and is correct 
          resolve(data.count);
        }));
  }

the console output is something like :

{__zone_symbol__state: null, __zone_symbol__value: Array(0)}
__zone_symbol__state:true
__zone_symbol__value:3

how can I solve this?

count(post.id).then(count => {
   this.count = count;
});
2 Likes

Do not do this. It is an antipattern. Study the code in the Angular HttpClient docs.

3 Likes