欢迎各位兄弟 发布技术文章
这里的技术是共享的
不建议使用以下ngrx select。
this.store.select(state => state.academy.academy).subscribe((academy) => {
this.academy = academy;
});
我在store.d.ts找到了
@deprecated from 6.1.0. Use the pipeable `select` operator instead.
那么...正确的语法是什么?
我尝试
this.store.pipe(select(state => state.academy.academy).subscribe((academy) => {
this.academy = academy;
}))
错误:找不到名称“选择”。您的意思是“ onselect”吗?
ngrx分享改善这个问题18年8月3日在12:27 问米哈利斯2,745添加评论
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;
});
}
}
分享改善这个答案18年8月3日在12:40 回答米哈利斯2,745添加评论11
根据NgRx 7,select
不建议使用此方法。
有关更多信息,请参见相关的请求请求。
分享改善这个答案18年12月25日在10:40 回答timdeschryver5,052添加评论3
正如@Michalis所提到的,只需select
从获得@ngrx/store
。
选择器使您能够为应用程序状态编写读取模型。就CQRS架构模式而言,NgRx将读取模型(选择器)与写入模型(缩减器)分开。一种高级技术是将选择器与RxJS可管道运算符结合在一起。
此功能是在v5.0.0中添加的,此后this.store.select()
不推荐使用。但是,在版本v6.1.0中添加了相同的注意事项。随着Store<T>
自身的扩展Observable<T>
,它返回observable,它可以使用轻松地进行预订.subscribe()
或可以使用不同的补丁运算符进行操作/转换。
RxJS .pipe()
在v5.5中引入了pipable运算符。还有一个管道实用程序功能,可用于构建可重用的可管道运算符。在版本v5中,借助pipe()
自定义select
运算符来构建。查看此链接或下面给出的基本示例(忽略空状态),以了解更多信息。
import { select } from '@ngrx/store';
import { pipe } from 'rxjs';
import { filter } from 'rxjs/operators';
export const selectFilteredState = pipe(
select('sliceOfState'),
filter(state => state !== undefined)
);
store.pipe(selectFilteredState ).subscribe(/* .. */);
分享改善这个答案18年9月6日在10:34 回答哈迪克·皮特瓦1,097添加评论
Ask QuestionAsked Active 10 months agoViewed 9k times19
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'?
ngrxshareimprove this questionasked Aug 3 '18 at 12:27Michalis2,745add a comment
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;
});
}
}
shareimprove this answeranswered Aug 3 '18 at 12:40Michalis2,745add a comment11
As per NgRx 7, the select
method is un-deprecated.
For more info, see the associated Pull Request.
shareimprove this answeranswered Dec 25 '18 at 10:40timdeschryver5,052add a comment3
As @Michalis mentioned, just get select
from @ngrx/store
.
Selectors empower you to compose a read model for your application state. In terms of the CQRS architectural pattern, NgRx separates the read model (selectors) from the write model (reducers). An advanced technique is to combine selectors with RxJS pipeable operators.
This feature was added in v5.0.0, and since then this.store.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 .subscribe()
or can be manipulated/transformed using different patch operators.
RxJS introduced pipable operators and .pipe()
in v5.5. There is also a pipe utility function that can be used to build reusable pipeable operators. In release v5, with the help of pipe()
custom select
operator is built. Check out this link or basic example(ignore empty state) is given beneath, to learn more.
import { select } from '@ngrx/store';
import { pipe } from 'rxjs';
import { filter } from 'rxjs/operators';
export const selectFilteredState = pipe(
select('sliceOfState'),
filter(state => state !== undefined)
);
store.pipe(selectFilteredState ).subscribe(/* .. */);
shareimprove this answeranswered Sep 6 '18 at 10:34Hardik Pithva1,097add a comment