gpt4 book ai didi

angular - 类型 'take' ngrx/store 上不存在属性 'Store'

转载 作者:太空狗 更新时间:2023-10-29 17:08:03 32 4
gpt4 key购买 nike

在我的功能中选择状态时,我尝试使用属性“take”,但出现错误 Property 'take' does not exist on type 'Store<State> .拜托,有人知道发生了什么事吗?我想要这样做的原因是因为我必须确定用户何时单击了将我的模板更改为表单的“添加空间”按钮。由于此模式还会更改父项的模板,因此我使用 @ngrx/store 对其进行管理。

我的代码:

import { Component, Input, OnInit, OnDestroy } from '@angular/core';
import { NgForm } from '@angular/forms';
import { Store } from '@ngrx/store';
import { Subscription } from 'rxjs/Subscription';

import { Space } from '../../../shared/space.model';
// import { SpacesService } from '../../spaces.service';
import * as SpacesActions from '../../store/spaces.actions';
import * as fromSpaces from '../../store/spaces.reducers';

@Component({
selector: 'app-space-item',
templateUrl: './space-item.component.html',
styleUrls: ['./space-item.component.scss']
})
export class SpaceItemComponent implements OnInit, OnDestroy {
@Input() space: Space;
@Input() index: number;
private addMode: boolean;
private editMode = false;
// updatedSpaceName: string;
// updatedSpace: Space;
private subscription: Subscription;
updatedSpaceName: string;
updatedPicture: string;

constructor(
// private spacesService: SpacesService,
private store: Store<fromSpaces.FeatureState>) { }

ngOnInit() {
this.subscription = this.store.select('spaces')
.take(1)
.subscribe(
data => {
if (data.addMode) {
this.addMode = data.addMode;
} else {
this.addMode = false;
}
}
);
}
ngOnDestroy() {
this.subscription.unsubscribe();
}

onEnableEdit() {
this.editMode = true;

this.updatedSpaceName = this.space.name;
this.updatedPicture = this.space.picture;
// console.log(this.updatedSpace);

}
onUpdate() {
this.onCancelEdit();
const updatedSpace = new Space(this.updatedSpaceName, this.updatedPicture);
// this.spacesService.updateSpace(updatedSpace, this.index);
this.store.dispatch(new SpacesActions.UpdateSpace({index: this.index, updatedSpace}));
}

onCancelEdit() {
this.editMode = false;
// this.updatedSpace = this.space;
}

onCancelAdd() {
// this.spacesService.addModeActivated.next(false);
this.store.dispatch(new SpacesActions.SwitchAddMode(false));
}

onDelete() {
// this.spacesService.deleteSpace(this.index);
this.store.dispatch(new SpacesActions.DeleteSpace(this.index));
}

onAddSpace(form: NgForm) {
const value = form.value;
const newSpace: Space = new Space(value.spaceName);

// this.spacesService.addSpace(newSpace);
this.store.dispatch(new SpacesActions.AddSpace(newSpace));
}
}

最佳答案

尝试导入它

 import 'rxjs/add/operator/take'; 

对于 Angular > 6,Angular 应用程序包的大小使用 lettable 运算符减小了,因为它们是tree-shakable

import { take } from 'rxjs/operators';
...

this.store.select('spaces').pipe(take(1)).subscribe();

关于angular - 类型 'take' ngrx/store 上不存在属性 'Store<State>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47252892/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com