Как изменить объект наблюдаемого в угловом?

#angular

#угловой

Вопрос:

У меня есть наблюдаемая ведьма, я получаю данные с сервера, и мне нужно, чтобы init отфильтровал эти данные и использовал их в проекте. Как мы можем сделать это в angular ?

 //get data from server this.sites = _httpClient.getlt;IModel[]gt;('api/mysites');  
 ngOnInit(): void {  //there I show data from server  this.sites.subscribe(x=gt; console.log('first console', x));    //and there I need to have filtred data   this.sites.subscribe(x=gt; console.log('second console', x));  }  

Комментарии:

1. это.сайты.труба(фильтр(x =gt; x )).подписка(x =gt;gt; x)

Ответ №1:

Если вам нужно отфильтровать данные, лучше всего использовать фильтрующую трубу:

 ngOnInit(): void {  this.sites  .pipe(filter(x =gt; // filter data here))  .subscribe(x=gt; console.log('first console', x));   // 'first console' will print your filtered data }  

Ответ №2:

 You can Use Pipes to transform your data once you get the value from the Server  https://angular.io/guide/pipes Refer this for more information on transforming data  
 this.sites = _httpClient.getlt;IModel[]gt;('api/mysites').pipe(    );   ngOnInit(): void {  //there I show data from server  this.sites.subscribe(x=gt; console.log('first console', x));    //and there I need to have filtred data   this.sites.subscribe(x=gt; console.log('second console', x));   }