根据 NGXS 文档,以下是所有有效代码:
import { Select } from '@ngxs/store';
import { ZooState, ZooStateModel } from './zoo.state';
@Component({ ... })
export class ZooComponent {
// Reads the name of the state from the state class
@Select(ZooState) animals$: Observable<string[]>;
// Uses the pandas memoized selector to only return pandas
@Select(ZooState.pandas) pandas$: Observable<string[]>;
// Also accepts a function like our select method
@Select(state => state.zoo.animals) animals$: Observable<string[]>;
// Reads the name of the state from the parameter
@Select() zoo$: Observable<ZooStateModel>;
}
我的问题是关于第三个@Select。究竟,装饰器和/或框架如何知道应该在 lambda 中使用哪个状态?这里没有什么明显的说“这个组件使用 ZooState 作为它的状态对象”,那么如何确定要查看的正确状态切片呢?
作为记录,这种模式似乎确实工作得很好——我只是有点难过如何。