浏览代码

commit modif

placidenduwayo 2 年前
父节点
当前提交
eb67f85646

+ 1
- 1
src/app/pages/companies-manager/companies-management/companies-management.component.html 查看文件

@@ -1,7 +1,7 @@
1 1
 <div class="container">
2 2
   <app-company-nav-bar></app-company-nav-bar>
3 3
 
4
-  <ng-container *ngIf="companyState"  [ngSwitch]="companyState.msgState">
4
+  <ng-container *ngIf="companyState$ |async as companyState"  [ngSwitch]="companyState.msgState">
5 5
 
6 6
     <ng-container *ngSwitchCase="msgState.LOADING">
7 7
       {{companyState.msgState}}

+ 6
- 5
src/app/pages/companies-manager/companies-management/companies-management.component.ts 查看文件

@@ -1,7 +1,8 @@
1
+import { Observable } from 'rxjs';
1 2
 import { MsgState } from './../../../ngrx/msg.state';
2 3
 import { CompanyState } from './../../../ngrx/companies/company.state';
3 4
 import { Component, OnInit } from '@angular/core';
4
-import { Store } from '@ngrx/store';
5
+import { select, Store } from '@ngrx/store';
5 6
 
6 7
 @Component({
7 8
   selector: 'app-companies-management',
@@ -12,14 +13,14 @@ export class CompaniesManagementComponent implements OnInit {
12 13
 
13 14
   constructor(private store: Store<{companyReducerKey: CompanyState}>) { }
14 15
 
15
-  companyState!: CompanyState;
16
+  companyState$!: Observable<CompanyState>;
16 17
   msgState = MsgState;
17 18
 
18 19
   ngOnInit(): void {
19 20
 
20
-    this.store.subscribe( state =>{
21
-      this.companyState = state.companyReducerKey;
22
-    })
21
+    this.companyState$ = this.store.pipe(
22
+      select( state => state.companyReducerKey)
23
+    );
23 24
   }
24 25
 
25 26
 }

Powered by TurnKey Linux.