Browse Source

Refactor to use Angular's new output() function

Replaces EventEmitter and @Output() with the new output() function in chart, tree, and test components. This modernizes the codebase to align with recent Angular best practices and reduces boilerplate.
pull/24766/head
Fahri Gedik 9 months ago
parent
commit
a29326402b
  1. 10
      npm/ng-packs/packages/components/chart.js/src/chart.component.ts
  2. 13
      npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts
  3. 8
      npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts

10
npm/ng-packs/packages/components/chart.js/src/chart.component.ts

@ -4,14 +4,13 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
ElementRef, ElementRef,
EventEmitter,
Input, Input,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
Output,
SimpleChanges, SimpleChanges,
ViewChild, ViewChild,
inject inject,
output,
} from '@angular/core'; } from '@angular/core';
let Chart: any; let Chart: any;
@ -53,9 +52,8 @@ export class ChartComponent implements AfterViewInit, OnDestroy, OnChanges {
@Input() responsive = true; @Input() responsive = true;
@Output() dataSelect = new EventEmitter(); readonly dataSelect = output<any>();
readonly initialized = output<boolean>();
@Output() initialized = new EventEmitter<boolean>();
@ViewChild('canvas') canvas!: ElementRef<HTMLCanvasElement>; @ViewChild('canvas') canvas!: ElementRef<HTMLCanvasElement>;

13
npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts

@ -3,11 +3,10 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
ContentChild, ContentChild,
EventEmitter,
inject, inject,
Input, Input,
OnInit, OnInit,
Output, output,
TemplateRef, TemplateRef,
ViewEncapsulation, ViewEncapsulation,
} from '@angular/core'; } from '@angular/core';
@ -63,11 +62,11 @@ export class TreeComponent implements OnInit {
@ContentChild('menu') menu: TemplateRef<any>; @ContentChild('menu') menu: TemplateRef<any>;
@ContentChild(TreeNodeTemplateDirective) customNodeTemplate: TreeNodeTemplateDirective; @ContentChild(TreeNodeTemplateDirective) customNodeTemplate: TreeNodeTemplateDirective;
@ContentChild(ExpandedIconTemplateDirective) expandedIconTemplate: ExpandedIconTemplateDirective; @ContentChild(ExpandedIconTemplateDirective) expandedIconTemplate: ExpandedIconTemplateDirective;
@Output() readonly checkedKeysChange = new EventEmitter(); readonly checkedKeysChange = output<any>();
@Output() readonly expandedKeysChange = new EventEmitter<string[]>(); readonly expandedKeysChange = output<string[]>();
@Output() readonly selectedNodeChange = new EventEmitter(); readonly selectedNodeChange = output<any>();
@Output() readonly dropOver = new EventEmitter<DropEvent>(); readonly dropOver = output<DropEvent>();
@Output() readonly nzExpandChange = new EventEmitter<NzFormatEmitEvent>(); readonly nzExpandChange = output<NzFormatEmitEvent>();
@Input() noAnimation = true; @Input() noAnimation = true;
@Input() draggable: boolean; @Input() draggable: boolean;
@Input() checkable: boolean; @Input() checkable: boolean;

8
npm/ng-packs/packages/core/src/lib/tests/replaceable-template.directive.spec.ts

@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, Output, inject } from '@angular/core'; import { Component, Input, inject, output } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest'; import { createDirectiveFactory, SpectatorDirective } from '@ngneat/spectator/vitest';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
@ -18,11 +18,9 @@ class DefaultComponent {
@Input() @Input()
twoWay: boolean; twoWay: boolean;
@Output() readonly twoWayChange = output<boolean>();
readonly twoWayChange = new EventEmitter<boolean>();
@Output() readonly someOutput = output<string>();
readonly someOutput = new EventEmitter<string>();
setTwoWay(value) { setTwoWay(value) {
this.twoWay = value; this.twoWay = value;

Loading…
Cancel
Save