How to Pass data from child to parent component Angular

Register the EventEmitter in your child component as the @Output: @Output() onDatePicked = new EventEmitter<any>(); Emit value on click: public pickDate(date: any): void { this.onDatePicked.emit(date); } Listen for the events in your parent component’s template: <div> <calendar (onDatePicked)=”doSomething($event)”></calendar> </div> and in the parent component: public doSomething(date: any):void { console.log(‘Picked date: ‘, date); } It’s also … Read more

How to manage Angular2 “expression has changed after it was checked” exception when a component property depends on current datetime

Run change detection explicitly after the change: import { ChangeDetectorRef } from ‘@angular/core’; constructor(private cdRef:ChangeDetectorRef) {} ngAfterViewChecked() { console.log( “! changement de la date du composant !” ); this.dateNow = new Date(); this.cdRef.detectChanges(); }

Angular – shared service between components doesn’t work

If you are providing your DataService inside the providers array of your @Component annotation, @Component({ … providers: [DataService], })… this service will be a singleton (it will create a new instance) for this component (and it’s children if they have not provided this service under their annotation also). If you want to use this service … Read more

RxJS: takeUntil() Angular component’s ngOnDestroy()

You could leverage a ReplaySubject for that: EDIT: Different since RxJS 6.x: Note the use of the pipe() method. class myComponent { private destroyed$: ReplaySubject<boolean> = new ReplaySubject(1); constructor( private serviceA: ServiceA, private serviceB: ServiceB, private serviceC: ServiceC) {} ngOnInit() { this.serviceA .pipe(takeUntil(this.destroyed$)) .subscribe(…); this.serviceB .pipe(takeUntil(this.destroyed$)) .subscribe(…); this.serviceC .pipe(takeUntil(this.destroyed$)) .subscribe(…); } ngOnDestroy() { this.destroyed$.next(true); this.destroyed$.complete(); … Read more

Use component in itself recursively to create a tree

update forwardRef() isn’t required anymore because directives was moved to NgModule.declarations and therefore recursive components don’t need to be registered on themselves as directives anymore. Angular 4.x.x Plunker example original That supported. You just need to add the component to directives: [] in its @Component() decorator. Because the decorator comes before the class and classes … Read more

How to free a component in Android / iOS

Update for 10.4 Delphi 10.4 Sydney unified memory management across all platforms and removed ARC compiler. In other words, all platforms now follow the same memory management rules as the Windows platform. DisposeOf vs Free in classic (non ARC) compiler DisposeOf on classic compiler calls Free and functionally behaves the same DisposeOf is left for … Read more

Why shouldn’t you extend JFrame and other components? [duplicate]

Generally speaking, extending the component tends to be done strictly to use the component. This severely limits your options in unnecessary ways in terms of design, so that your classes can’t extend different classes, you can’t hide the JFrame’s methods causing it to be more difficult to maintain and easier to trigger unexpected bugs when … Read more