Skip to content

Commit 3e7fad5

Browse files
committed
feat(angular): use ComponentRef.setInput() API by default
1 parent 9d781db commit 3e7fad5

File tree

7 files changed

+33
-61
lines changed

7 files changed

+33
-61
lines changed

packages/angular/common/src/providers/angular-delegate.ts

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import {
2020

2121
import { NavParams } from '../directives/navigation/nav-params';
2222

23-
import { ConfigToken } from './config';
24-
2523
// Token for injecting the modal element
2624
export const IonModalToken = new InjectionToken<HTMLIonModalElement>('IonModalToken');
2725

@@ -31,7 +29,6 @@ export const IonModalToken = new InjectionToken<HTMLIonModalElement>('IonModalTo
3129
export class AngularDelegate {
3230
private zone = inject(NgZone);
3331
private applicationRef = inject(ApplicationRef);
34-
private config = inject(ConfigToken);
3532

3633
create(
3734
environmentInjector: EnvironmentInjector,
@@ -43,8 +40,7 @@ export class AngularDelegate {
4340
injector,
4441
this.applicationRef,
4542
this.zone,
46-
elementReferenceKey,
47-
this.config.useSetInputAPI ?? false
43+
elementReferenceKey
4844
);
4945
}
5046
}
@@ -58,8 +54,7 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
5854
private injector: Injector,
5955
private applicationRef: ApplicationRef,
6056
private zone: NgZone,
61-
private elementReferenceKey?: string,
62-
private enableSignalsSupport?: boolean
57+
private elementReferenceKey?: string
6358
) {}
6459

6560
attachViewToDom(container: any, component: any, params?: any, cssClasses?: string[]): Promise<any> {
@@ -92,8 +87,7 @@ export class AngularFrameworkDelegate implements FrameworkDelegate {
9287
component,
9388
componentProps,
9489
cssClasses,
95-
this.elementReferenceKey,
96-
this.enableSignalsSupport
90+
this.elementReferenceKey
9791
);
9892
resolve(el);
9993
});
@@ -130,8 +124,7 @@ export const attachView = (
130124
component: any,
131125
params: any,
132126
cssClasses: string[] | undefined,
133-
elementReferenceKey: string | undefined,
134-
enableSignalsSupport: boolean | undefined
127+
elementReferenceKey: string | undefined
135128
): any => {
136129
/**
137130
* Wraps the injector with a custom injector that
@@ -185,37 +178,28 @@ export const attachView = (
185178
);
186179
}
187180

181+
const { modal, popover, ...otherParams } = params;
188182
/**
189-
* Angular 14.1 added support for setInput
190-
* so we need to fall back to Object.assign
191-
* for Angular 14.0.
183+
* Any key/value pairs set in componentProps
184+
* must be set as inputs on the component instance.
192185
*/
193-
if (enableSignalsSupport === true && componentRef.setInput !== undefined) {
194-
const { modal, popover, ...otherParams } = params;
195-
/**
196-
* Any key/value pairs set in componentProps
197-
* must be set as inputs on the component instance.
198-
*/
199-
for (const key in otherParams) {
200-
componentRef.setInput(key, otherParams[key]);
201-
}
186+
for (const key in otherParams) {
187+
componentRef.setInput(key, otherParams[key]);
188+
}
202189

203-
/**
204-
* Using setInput will cause an error when
205-
* setting modal/popover on a component that
206-
* does not define them as an input. For backwards
207-
* compatibility purposes we fall back to using
208-
* Object.assign for these properties.
209-
*/
210-
if (modal !== undefined) {
211-
Object.assign(instance, { modal });
212-
}
190+
/**
191+
* Using setInput will cause an error when
192+
* setting modal/popover on a component that
193+
* does not define them as an input. For backwards
194+
* compatibility purposes we fall back to using
195+
* Object.assign for these properties.
196+
*/
197+
if (modal !== undefined) {
198+
Object.assign(instance, { modal });
199+
}
213200

214-
if (popover !== undefined) {
215-
Object.assign(instance, { popover });
216-
}
217-
} else {
218-
Object.assign(instance, params);
201+
if (popover !== undefined) {
202+
Object.assign(instance, { popover });
219203
}
220204
}
221205
if (cssClasses) {

packages/angular/src/ionic-module.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,14 @@ const DECLARATIONS = [
5252
IonMaxValidator,
5353
];
5454

55-
type OptInAngularFeatures = {
56-
useSetInputAPI?: boolean;
57-
};
58-
5955
@NgModule({
6056
declarations: DECLARATIONS,
6157
exports: DECLARATIONS,
6258
providers: [ModalController, PopoverController],
6359
imports: [CommonModule],
6460
})
6561
export class IonicModule {
66-
static forRoot(config: IonicConfig & OptInAngularFeatures = {}): ModuleWithProviders<IonicModule> {
62+
static forRoot(config: IonicConfig = {}): ModuleWithProviders<IonicModule> {
6763
return {
6864
ngModule: IonicModule,
6965
providers: [

packages/angular/standalone/src/providers/ionic-angular.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import type { IonicConfig } from '@ionic/core/components';
88
import { ModalController } from './modal-controller';
99
import { PopoverController } from './popover-controller';
1010

11-
type OptInAngularFeatures = {
12-
useSetInputAPI?: boolean;
13-
};
14-
15-
export const provideIonicAngular = (config: IonicConfig & OptInAngularFeatures = {}): EnvironmentProviders => {
11+
export const provideIonicAngular = (config: IonicConfig = {}): EnvironmentProviders => {
1612
return makeEnvironmentProviders([
1713
{
1814
provide: ConfigToken,

packages/angular/test/apps/ng16/src/app/lazy/version-test/modal-nav-params/nav-root.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { JsonPipe } from "@angular/common";
21
import { Component, Input, OnInit } from "@angular/core";
32

43
import { IonicModule } from "@ionic/angular";
@@ -19,7 +18,7 @@ let rootParamsException = false;
1918
{{ hasException ? 'ERROR' : 'OK' }}
2019
`,
2120
standalone: true,
22-
imports: [IonicModule, JsonPipe]
21+
imports: [IonicModule]
2322
})
2423
export class NavRootComponent implements OnInit {
2524

packages/angular/test/apps/ng17/src/app/lazy/version-test/modal-nav-params/nav-root.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { JsonPipe } from "@angular/common";
21
import { Component, Input, OnInit } from "@angular/core";
32

43
import { IonicModule } from "@ionic/angular";
@@ -19,7 +18,7 @@ let rootParamsException = false;
1918
{{ hasException ? 'ERROR' : 'OK' }}
2019
`,
2120
standalone: true,
22-
imports: [IonicModule, JsonPipe]
21+
imports: [IonicModule]
2322
})
2423
export class NavRootComponent implements OnInit {
2524

packages/angular/test/apps/ng18/src/app/lazy/version-test/modal-nav-params/nav-root.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { JsonPipe } from "@angular/common";
2-
import { Component, OnInit } from "@angular/core";
1+
import { Component, Input, OnInit } from "@angular/core";
32

43
import { IonicModule } from "@ionic/angular";
54

@@ -19,11 +18,11 @@ let rootParamsException = false;
1918
{{ hasException ? 'ERROR' : 'OK' }}
2019
`,
2120
standalone: true,
22-
imports: [IonicModule, JsonPipe]
21+
imports: [IonicModule]
2322
})
2423
export class NavRootComponent implements OnInit {
2524

26-
params: any;
25+
@Input() params: any;
2726

2827
ngOnInit() {
2928
if (this.params === undefined) {

packages/angular/test/base/src/app/lazy/version-test/modal-nav-params/nav-root.component.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, OnInit } from "@angular/core";
1+
import { Component, Input, OnInit } from "@angular/core";
22

33
import { IonicModule } from "@ionic/angular";
44

@@ -14,14 +14,13 @@ let rootParamsException = false;
1414

1515
@Component({
1616
selector: 'app-modal-content',
17-
template: `
18-
{{ hasException ? 'ERROR' : 'OK' }}
19-
`,
17+
template: `{{ hasException ? 'ERROR' : 'OK' }}`,
18+
standalone: true,
2019
imports: [IonicModule]
2120
})
2221
export class NavRootComponent implements OnInit {
2322

24-
params: any;
23+
@Input() params: any;
2524

2625
ngOnInit() {
2726
if (this.params === undefined) {

0 commit comments

Comments
 (0)