1919 * waive the privileges and immunities granted to it by virtue of its status
2020 * as an Intergovernmental Organization or submit itself to any jurisdiction.
2121*/
22- import { OnInit , OnDestroy } from '@angular/core' ;
23-
24- import { Subscription } from 'rxjs/Subscription' ;
22+ import { OnInit , OnDestroy , ChangeDetectorRef } from '@angular/core' ;
2523
2624import { AbstractTrackerComponent } from '../abstract-tracker' ;
2725
2826import { AppGlobalsService , PathUtilService } from '../shared/services' ;
27+ import { ValidationError } from '../shared/interfaces' ;
28+ import { Subscription } from 'rxjs/Subscription' ;
2929
3030/**
3131 * This is the base class for fields
@@ -40,39 +40,37 @@ export abstract class AbstractFieldComponent
4040 implements OnInit , OnDestroy {
4141
4242 path : Array < any > ;
43- errors : Array < Object > = [ ] ;
44- errorsSubscription : Subscription ;
43+ externalErrors : Array < ValidationError > = [ ] ;
44+ internalErrors : Array < ValidationError > = [ ] ;
45+ externalCategorizedErrorSubscription : Subscription ;
4546
4647 constructor ( public appGlobalsService : AppGlobalsService ,
47- public pathUtilService : PathUtilService ) {
48+ public pathUtilService : PathUtilService ,
49+ public changeDetectorRef : ChangeDetectorRef ) {
4850 super ( ) ;
4951 }
5052
5153 ngOnInit ( ) {
52- this . errorsSubscription = this . appGlobalsService
53- . globalErrorsSubject
54- . subscribe ( ( globalErrors ) => {
55- this . errors = globalErrors [ this . pathString ] || [ ] ;
54+ this . externalCategorizedErrorSubscription = this . appGlobalsService . externalCategorizedErrorsSubject
55+ . subscribe ( externalCategorizedErrorMap => {
56+ this . externalErrors = externalCategorizedErrorMap . Errors [ this . pathString ] || [ ] ;
57+ this . changeDetectorRef . markForCheck ( ) ;
5658 } ) ;
5759 }
5860
5961 ngOnDestroy ( ) {
60- if ( this . errorsSubscription ) {
61- this . errorsSubscription . unsubscribe ( ) ;
62- }
63- }
64-
65- get errorNgClass ( ) : Object {
66- return {
67- error : this . errors . length > 0
68- } ;
62+ this . externalCategorizedErrorSubscription . unsubscribe ( ) ;
6963 }
7064
7165 get isErrorTooltipEnabled ( ) : boolean {
72- return this . errors && this . errors . length > 0 ;
66+ return this . hasErrors ;
7367 }
7468
7569 get pathString ( ) : string {
7670 return this . pathUtilService . toPathString ( this . path ) ;
7771 }
72+
73+ get hasErrors ( ) {
74+ return this . externalErrors . length > 0 || this . internalErrors . length > 0 ;
75+ }
7876}
0 commit comments