Skip to content

Commit 082924f

Browse files
committed
chore(components): Change event listeners to HostListener and template binding
1 parent c89c369 commit 082924f

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

projects/igniteui-angular/src/lib/directives/button/button.directive.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import {
33
ElementRef,
44
EventEmitter,
55
HostBinding,
6+
HostListener,
67
Input,
78
Output,
89
Renderer2,
910
booleanAttribute,
10-
AfterContentInit,
11-
OnDestroy
1211
} from '@angular/core';
1312
import { mkenum } from '../../core/utils';
1413
import { IBaseEventArgs } from '../../core/utils';
@@ -47,7 +46,7 @@ export type IgxButtonType = typeof IgxButtonType[keyof typeof IgxButtonType];
4746
selector: '[igxButton]',
4847
standalone: true
4948
})
50-
export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterContentInit, OnDestroy {
49+
export class IgxButtonDirective extends IgxButtonBaseDirective {
5150
private static ngAcceptInputType_type: IgxButtonType | '';
5251

5352
/**
@@ -93,7 +92,8 @@ export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterC
9392
*/
9493
private _selected = false;
9594

96-
private emitSelected() {
95+
@HostListener('click')
96+
protected emitSelected() {
9797
this.buttonSelected.emit({
9898
button: this
9999
});
@@ -127,15 +127,6 @@ export class IgxButtonDirective extends IgxButtonBaseDirective implements AfterC
127127
super(element);
128128
}
129129

130-
public ngAfterContentInit() {
131-
this.emitSelected = this.emitSelected.bind(this);
132-
this.nativeElement.addEventListener('click', this.emitSelected);
133-
}
134-
135-
public ngOnDestroy(): void {
136-
this.nativeElement.removeEventListener('click', this.emitSelected);
137-
}
138-
139130
/**
140131
* Sets the type of the button.
141132
*

projects/igniteui-angular/src/lib/directives/scroll-inertia/scroll_inertia.directive.spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
OnInit,
66
ViewChild,
77
ElementRef,
8-
OnDestroy,
98
} from '@angular/core';
109
import { TestBed, ComponentFixture, fakeAsync, tick, waitForAsync } from '@angular/core/testing';
1110
import { IgxScrollInertiaDirective } from './scroll_inertia.directive';
@@ -348,13 +347,13 @@ export class IgxTestScrollInertiaDirective extends IgxScrollInertiaDirective {
348347
<div #container style='width:calc(100% - 50px); height: 500px; float: left;'>
349348
<ng-template igxTestScrollInertia #scrInertiaContainer></ng-template>
350349
</div>
351-
<div #scrBar [style.height]='height' style='overflow: auto; width: 50px; float:right;'>
350+
<div #scrBar [style.height]='height' style='overflow: auto; width: 50px; float:right;' (scroll)="this.onScroll($event)">
352351
<div [style.height]='innerHeight' [style.width]='innerWidth'></div>
353352
</div>
354353
`,
355354
imports: [IgxTestScrollInertiaDirective]
356355
})
357-
export class ScrollInertiaComponent implements OnInit, OnDestroy {
356+
export class ScrollInertiaComponent implements OnInit {
358357
@ViewChild('container', { static: true }) public container: ElementRef;
359358
@ViewChild('scrBar', { static: true }) public scrollContainer: ElementRef;
360359
@ViewChild('scrInertiaContainer', { read: IgxTestScrollInertiaDirective, static: true })
@@ -370,9 +369,6 @@ export class ScrollInertiaComponent implements OnInit, OnDestroy {
370369

371370
public ngOnInit() {
372371
this.scrInertiaDir.IgxScrollInertiaScrollContainer = this.scrollContainer.nativeElement;
373-
374-
this.onScroll = this.onScroll.bind(this);
375-
this.scrollContainer.nativeElement.addEventListener('scroll', this.onScroll);
376372
}
377373

378374
public onScroll(evt) {
@@ -386,8 +382,4 @@ export class ScrollInertiaComponent implements OnInit, OnDestroy {
386382
this.scrTopStepArray.push(calcScrollStep);
387383
this.scrLeftStepArray.push(calcScrollLeftStep);
388384
}
389-
390-
public ngOnDestroy(): void {
391-
this.scrollContainer.nativeElement.removeEventListener('scroll', this.onScroll);
392-
}
393385
}

0 commit comments

Comments
 (0)