Skip to content

Commit 708b121

Browse files
pankajparkarpavankjaddaCopilot
authored
feat: update using signal API -> input, computed, output, viewChild (ng-select#2584)
* feat(signals-migration): Ran migration command for input output and inject * feat(signals-migration): Assignment issues are addressed * feat(signals-migration): Unit tests are update to modify properties * chore(signals-migration): Remove unwanted constructors * test(signals-migration): Fixed unit test cases * test(signals-migration): fix more ng-select component tests * test(signals-migration): fixed 4 more tests * test(signals-migration): fixed 1 more test * test(signals-migration): added conditional evaluation of signal value * test(signals-migration): generic value evaluation function * test(signals-migration): solved the ng-option component test issue * test(signals-migration): solved 2 more tests * test(signals-migration): fixed one more tests * test(signals-migration): migrate view queries * test(signals-migration): moved clearSearchOnAdd from Input to input signal * test(signals-migration): converted compareWith to input signal * test(signals-migration): created deselectOnClickValue computed value * test(signals-migration): _disabled to signal to remove cd manual run * test(signals-migration): composition start tests addressed * test(signals-migration): remaining test address * test(signals-migration): convert items @input to use input signal * chore(signals-migration): migration of ContentChildren with contentChildren signal * test(signals-migration): NgOptionHighlightDirective test resolved * chore(signals-migration): small chore work * chore(signals-migration): toString inside a brackets * chore(signals-migration): update 1st update after label update * Update src/ng-select/lib/items-list.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/ng-select/lib/ng-dropdown-panel.component.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore(signals-migration): updated code based on copilot suggestions * Update src/ng-select/lib/ng-select.component.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore(signals-migration): read compareWith() input * chore(signals-migration): used direct signal reference instead of using extra variable * test(signals-migration): declare event object which wasn't defined --------- Co-authored-by: Pavan Kumar Jadda <17564080+pavankjadda@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4df2c7c commit 708b121

45 files changed

Lines changed: 1200 additions & 1142 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"repository": "ng-select/ng-select",
33
"scripts": {
4+
"ng": "ng",
45
"build": "ng build ng-select && ng build ng-option-highlight && yarn build:themes && yarn copy-sass",
56
"build:demo": "ng build demo --configuration production && yarn copy-examples",
67
"build:themes": "sass --style=compressed src/ng-select/themes/:dist/ng-select/themes",

src/demo/app/app.component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, HostBinding, inject, OnInit } from '@angular/core';
22
import { ActivatedRoute, NavigationEnd, Router, RouterOutlet } from '@angular/router';
33
import { Title } from '@angular/platform-browser';
44
import { filter, map, mergeMap } from 'rxjs/operators';
@@ -13,19 +13,19 @@ import { LayoutSidenavComponent } from './layout/sidenav-component';
1313
changeDetection: ChangeDetectionStrategy.Default,
1414
imports: [LayoutHeaderComponent, LayoutSidenavComponent, RouterOutlet],
1515
})
16-
export class AppComponent {
16+
export class AppComponent implements OnInit {
17+
private router = inject(Router);
18+
private activatedRoute = inject(ActivatedRoute);
19+
private titleService = inject(Title);
20+
private config = inject(NgSelectConfig);
21+
1722
title: string;
1823
version: string = window['ngSelectVersion'];
1924
exampleSourceUrl: string;
2025
dir: 'ltr' | 'rtl' = 'ltr';
2126
theme: 'default' | 'ant' | 'material' = 'default';
2227

23-
constructor(
24-
private router: Router,
25-
private activatedRoute: ActivatedRoute,
26-
private titleService: Title,
27-
private config: NgSelectConfig,
28-
) {
28+
constructor() {
2929
this.config.placeholder = 'Select item';
3030
// This could be useful if you want to use appendTo in entire application without explicitly defining it. (eg: appendTo = 'body')
3131
this.config.appendTo = null;

src/demo/app/examples/append-to-example/append-to-example.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { DataService } from '../data.service';
33
import { FormsModule } from '@angular/forms';
44
import { AsyncPipe } from '@angular/common';
@@ -11,13 +11,13 @@ import { NgSelectComponent } from '@ng-select/ng-select';
1111
imports: [NgSelectComponent, FormsModule, AsyncPipe],
1212
})
1313
export class AppendToExampleComponent implements OnInit {
14+
private dataService = inject(DataService);
15+
1416
people: any = [];
1517
selected: any;
1618
selected2: any;
1719
selected3: any;
1820

19-
constructor(private dataService: DataService) {}
20-
2121
ngOnInit() {
2222
this.people = this.dataService.getPeople();
2323
}

src/demo/app/examples/data-source-array-example/data-source-array-example.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { DataService, Person } from '../data.service';
33
import { FormsModule } from '@angular/forms';
44
import { NgSelectComponent } from '@ng-select/ng-select';
@@ -10,14 +10,14 @@ import { NgSelectComponent } from '@ng-select/ng-select';
1010
imports: [NgSelectComponent, FormsModule],
1111
})
1212
export class DataSourceArrayExampleComponent implements OnInit {
13+
private dataService = inject(DataService);
14+
1315
people: Person[] = [];
1416
selectedPersonId = '5a15b13c36e7a7f00cf0d7cb';
1517

1618
selectedSimpleItem = 'Two';
1719
simpleItems = [];
1820

19-
constructor(private dataService: DataService) {}
20-
2121
ngOnInit() {
2222
this.dataService.getPeople().subscribe((items) => (this.people = items));
2323
this.simpleItems = [true, 'Two', 3];

src/demo/app/examples/data-source-backend-example/data-source-backend-example.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { DataService, Person } from '../data.service';
33
import { Observable } from 'rxjs';
44
import { FormsModule } from '@angular/forms';
@@ -12,11 +12,11 @@ import { NgSelectComponent } from '@ng-select/ng-select';
1212
imports: [NgSelectComponent, FormsModule, AsyncPipe],
1313
})
1414
export class DataSourceBackendExampleComponent implements OnInit {
15+
private dataService = inject(DataService);
16+
1517
people$: Observable<Person[]>;
1618
selectedPersonId = '5a15b13c36e7a7f00cf0d7cb';
1719

18-
constructor(private dataService: DataService) {}
19-
2020
ngOnInit() {
2121
this.people$ = this.dataService.getPeople();
2222
}

src/demo/app/examples/data.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { Observable, of } from 'rxjs';
33
import { delay, map, tap } from 'rxjs/operators';
44
import { HttpClient } from '@angular/common/http';
@@ -19,9 +19,9 @@ export interface Person {
1919
providedIn: 'root',
2020
})
2121
export class DataService {
22-
private _gitHubAccountsCache = new Map<string, []>();
22+
private http = inject(HttpClient);
2323

24-
constructor(private http: HttpClient) {}
24+
private _gitHubAccountsCache = new Map<string, []>();
2525

2626
getGithubAccounts(term: string = null) {
2727
if (this._gitHubAccountsCache.has(term)) {

src/demo/app/examples/forms-async-data-example/forms-async-data-example.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
33
import { NgOptionTemplateDirective, NgSelectComponent, NgSelectComponent as NgSelectComponent_1 } from '@ng-select/ng-select';
44
import { delay } from 'rxjs/operators';
@@ -12,15 +12,13 @@ import { NgOptionHighlightDirective } from '@ng-select/ng-option-highlight';
1212
imports: [FormsModule, ReactiveFormsModule, NgSelectComponent_1, NgOptionTemplateDirective, NgOptionHighlightDirective],
1313
})
1414
export class FormsAsyncDataExampleComponent implements OnInit {
15+
private fb = inject(FormBuilder);
16+
private dataService = inject(DataService);
17+
1518
heroForm: FormGroup;
1619
albums = [];
1720
allAlbums = [];
1821

19-
constructor(
20-
private fb: FormBuilder,
21-
private dataService: DataService,
22-
) {}
23-
2422
ngOnInit() {
2523
this.loadAlbums();
2624
this.heroForm = this.fb.group({

src/demo/app/examples/forms-custom-template-example/forms-custom-template-example.component.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
33
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
44
import { DataService } from '../data.service';
@@ -19,15 +19,13 @@ import { NgOptionHighlightDirective } from '@ng-select/ng-option-highlight';
1919
],
2020
})
2121
export class FormsCustomTemplateExampleComponent implements OnInit {
22+
private fb = inject(FormBuilder);
23+
private modalService = inject(NgbModal);
24+
private dataService = inject(DataService);
25+
2226
heroForm: FormGroup;
2327
photos = [];
2428

25-
constructor(
26-
private fb: FormBuilder,
27-
private modalService: NgbModal,
28-
private dataService: DataService,
29-
) {}
30-
3129
ngOnInit() {
3230
this.loadPhotos();
3331

src/demo/app/examples/forms-multi-select-example/forms-multi-select-example.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
33
import { NgSelectComponent } from '@ng-select/ng-select';
44

@@ -9,6 +9,8 @@ import { NgSelectComponent } from '@ng-select/ng-select';
99
imports: [FormsModule, ReactiveFormsModule, NgSelectComponent],
1010
})
1111
export class FormsMultiSelectExampleComponent implements OnInit {
12+
private fb = inject(FormBuilder);
13+
1214
heroForm: FormGroup;
1315
isCitiesControlVisible = true;
1416
cities: any[] = [
@@ -18,8 +20,6 @@ export class FormsMultiSelectExampleComponent implements OnInit {
1820
{ id: 4, name: 'Pabradė' },
1921
];
2022

21-
constructor(private fb: FormBuilder) {}
22-
2323
ngOnInit() {
2424
this.heroForm = this.fb.group({
2525
selectedCitiesIds: [],

src/demo/app/examples/forms-single-select-example/forms-single-select-example.component.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
33
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
44
import { NgSelectComponent } from '@ng-select/ng-select';
@@ -10,18 +10,16 @@ import { NgSelectComponent } from '@ng-select/ng-select';
1010
imports: [FormsModule, ReactiveFormsModule, NgSelectComponent],
1111
})
1212
export class FormsSingleSelectExampleComponent implements OnInit {
13+
private fb = inject(FormBuilder);
14+
private modalService = inject(NgbModal);
15+
1316
heroForm: FormGroup;
1417
ages: any[] = [
1518
{ value: '<18', label: 'Under 18' },
1619
{ value: '18', label: '18' },
1720
{ value: '>18', label: 'More than 18' },
1821
];
1922

20-
constructor(
21-
private fb: FormBuilder,
22-
private modalService: NgbModal,
23-
) {}
24-
2523
ngOnInit() {
2624
this.heroForm = this.fb.group({
2725
age: [null, Validators.required],

0 commit comments

Comments
 (0)