Angular 角度,将选择器存储数据发送到子组件

Angular 角度,将选择器存储数据发送到子组件,angular,components,ngrx-store,Angular,Components,Ngrx Store,我想问一下有关将数据从选择器store-ngrx发送到子组件的解决方案 只是: public testValue; this.store$.select(selectorDataTest).subscribe( data => { this.testValue = data; } ); 在模板中: <child-component [testValue] = "testValue"></child-comp

我想问一下有关将数据从选择器store-ngrx发送到子组件的解决方案

只是:

public testValue;

 this.store$.select(selectorDataTest).subscribe(
        data => {
          this.testValue = data;
        }
    );
在模板中:

<child-component [testValue] = "testValue"></child-component>
我考虑异步等。

当您使用select从存储中获取一些数据时,它将作为可观察数据返回,请在管道中使用select,这就是您正确订阅此.store$.pipeselectordatatest的原因

如果您记得取消订阅,这种方法会更好,我有两种方法供您选择:

1.
dataSubscription: Subscription;

ngOnInit() {
  this.dataSubscription = this.store$.pipe(select(selectorDataTest))
    .subscribe(data => this.testValue = data);
}

ngOnDestroy() {
  this.dataSubscription.unsubscribe();
}
在您的子组件中

那么你的方法呢

<child-component [testValue] = "testValue"></child-component>
以及在parent.component.html上

当您使用select从存储中获取一些数据时,这些数据将作为可观察数据返回,请在管道中使用select,这就是您正确订阅此.store$.pipeselectordatatest的原因

如果您记得取消订阅,这种方法会更好,我有两种方法供您选择:

1.
dataSubscription: Subscription;

ngOnInit() {
  this.dataSubscription = this.store$.pipe(select(selectorDataTest))
    .subscribe(data => this.testValue = data);
}

ngOnDestroy() {
  this.dataSubscription.unsubscribe();
}
在您的子组件中

那么你的方法呢

<child-component [testValue] = "testValue"></child-component>
以及在parent.component.html上


我加了什么了吗?在它之后,我有一个错误:无法读取null的属性“xxx”。像错误的流量数据…我添加了什么?在它之后,我有一个错误:无法读取null的属性“xxx”。像错误的流量数据。。。
dataTest$: Observable<any>;

ngOnInit() {
  this.dataTest$ = this.store$.pipe(select(selectorDataTest));
}
<child-component [testValue]="testData$ | async"></child-component>
@Input() testValue: any;