根据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
我正在尝试创建一个NgXs ,但是当选择器被使用时,我会得到运行时的错误:
TypeError: Cannot read property 'x' of undefined
at my-state.state.ts:56
at wrappedSelectorFn (ngxs-store.js:2136)
at memoized (ngxs-store-internals.js:58)
at memoized (ngxs-store-internals.js:58)
at Store.selectSnapshot (ngxs-store.j
这似乎是一个相当常见的模式,所以我希望有人能帮忙。
我试图通过一个角度服务来揭露一个可以观察到的“事物”。我的服务需要首先获取内容列表,然后侦听添加的新内容。所以我有两个不同的服务请求,但是我试图将它们封装在一个可以观察到的东西中,这样消费组件就不必担心内部的问题了。
它看起来是这样的:
export class MyService {
constructor(private commService: CommService){}
get things(): Observable<Things[]> {
// how can I get the initial
我是NGXS的新手,我试图找出在使用NGXS成功/错误HTTP响应后发送UI toast通知的正确方式?我们是否应该在状态下处理它: @Action(SomeRequestSuccess)
public success(ctx: StateContext<SomeModel>, action: SomeRequestSuccess) {
// like this
this.store.dispatch([new SuccessToastNotification(msg)])
// or just use service
this.toast
我的应用程序里有个简单的服务。
import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';
@Injectable()
export class WizardDialogNavigationService {
public navAction$: Observable<any>;
private navActionSubject: Sub
我有一个返回可观察到的方法:
clockOut(): Observable<boolean> {
let isClockedOut = new Subject<boolean>();
isClockedOut.next(false);
// Some code to clock out and return x
if (x === true) {
isClockedOut.next(true);
}
return isClockedOut.asObservable();
}
我正在调用/订阅clock