Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ngrx 6.1.0 - Select is deprecated - What is the new syntax?

Tags:

ngrx

The following ngrx select is deprecated.

this.store.select(state => state.academy.academy).subscribe((academy) => {     this.academy = academy; }); 

I found this at store.d.ts

@deprecated from 6.1.0. Use the pipeable `select` operator instead. 

So... what's the correct syntax?

I try

this.store.pipe(select(state => state.academy.academy).subscribe((academy) => {     this.academy = academy; })) 

Error: Cannot find name 'select'. Did you mean 'onselect'?

like image 682
Michalis Avatar asked Aug 03 '18 12:08

Michalis


People also ask

Is Select deprecated?

select() has been deprecated. However, notice for the same is added in release v6. 1.0. As Store<T> itself extends Observable<T> , it returns observable which can easily be subscribed using .

What is return of store select method in NgRx?

Store. select returns an observable that you can subscribe to either in your component or template via '|async'.


2 Answers

import {Component, OnInit} from '@angular/core';  import {Store, select} from '@ngrx/store';  import {AppState} from '../../../../../app.state';    @Component({     selector: 'app-layout',     templateUrl: './layout.component.html',     styleUrls: ['./layout.component.scss']  })  export class PageLayoutComponent implements OnInit {       academy;       constructor(        private store: Store<AppState>     ) {     }       ngOnInit() {        this.store.pipe(select((state: any) => state.academy.academy)).subscribe((academy) => {           this.academy = academy;        });     }      }
like image 83
Michalis Avatar answered Oct 06 '22 07:10

Michalis


As per NgRx 7, the select method is un-deprecated.

For more info, see the associated Pull Request.

like image 26
timdeschryver Avatar answered Oct 06 '22 09:10

timdeschryver