1
- import { Component , Input , ViewChild } from '@angular/core' ;
1
+ import { ChangeDetectionStrategy , ChangeDetectorRef , Component , Input , ViewChild } from '@angular/core' ;
2
2
import { Store } from '@ngxs/store' ;
3
3
import { ModalTemplate , SuiActiveModal , SuiModalService , TemplateModalConfig } from '@richardlt/ng2-semantic-ui' ;
4
4
import { PermissionValue } from 'app/model/permission.model' ;
@@ -10,10 +10,20 @@ import { finalize } from 'rxjs/operators';
10
10
@Component ( {
11
11
selector : 'app-labels-edit' ,
12
12
templateUrl : './labels.edit.component.html' ,
13
- styleUrls : [ './labels.edit.component.scss' ]
13
+ styleUrls : [ './labels.edit.component.scss' ] ,
14
+ changeDetection : ChangeDetectionStrategy . OnPush
14
15
} )
15
16
export class LabelsEditComponent {
16
- @Input ( ) project : Project ;
17
+ _project : Project ;
18
+ @Input ( 'project' ) set project ( data : Project ) {
19
+ this . _project = data ;
20
+ if ( this . _project ) {
21
+ this . labels = cloneDeep ( this . project . labels ) ;
22
+ }
23
+ }
24
+ get project ( ) {
25
+ return this . _project ;
26
+ }
17
27
18
28
@ViewChild ( 'labelsEditModal' , { static : false } )
19
29
public labelsEditModal : ModalTemplate < boolean , boolean , void > ;
@@ -27,7 +37,8 @@ export class LabelsEditComponent {
27
37
28
38
constructor (
29
39
private store : Store ,
30
- private _suiService : SuiModalService
40
+ private _suiService : SuiModalService ,
41
+ private _cd : ChangeDetectorRef
31
42
) {
32
43
33
44
}
@@ -37,7 +48,6 @@ export class LabelsEditComponent {
37
48
return ;
38
49
}
39
50
this . newLabel = new Label ( ) ;
40
- this . labels = cloneDeep ( this . project . labels ) ;
41
51
this . modalConfig = new TemplateModalConfig < boolean , boolean , void > ( this . labelsEditModal ) ;
42
52
this . modalConfig . mustScroll = true ;
43
53
this . modal = this . _suiService . open ( this . modalConfig ) ;
@@ -63,6 +73,7 @@ export class LabelsEditComponent {
63
73
} ) ) . pipe ( finalize ( ( ) => {
64
74
this . loading = false ;
65
75
this . newLabel = new Label ( ) ;
76
+ this . _cd . markForCheck ( ) ;
66
77
} ) ) . subscribe ( ( ) => {
67
78
if ( close ) {
68
79
this . modal . approve ( true ) ;
0 commit comments