Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular): use Ionic standalone components #1798

Merged
merged 13 commits into from
Oct 12, 2023
Merged
4 changes: 2 additions & 2 deletions angular-standalone/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"@angular/platform-browser": "^16.0.0",
"@angular/platform-browser-dynamic": "^16.0.0",
"@angular/router": "^16.0.0",
"@ionic/angular": "^7.0.0",
"ionicons": "^7.0.0",
"@ionic/angular": "7.3.4-dev.11694534020.12e16bee",
"ionicons": "7.1.3-dev.11694468279.1c23df00",
"rxjs": "~7.8.0",
"tslib": "^2.3.0",
"zone.js": "~0.13.0"
Expand Down
4 changes: 2 additions & 2 deletions angular-standalone/base/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { IonApp } from '@ionic/angular/standalone';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
standalone: true,
imports: [IonicModule],
imports: [IonApp],
})
export class AppComponent {
constructor() {}
Expand Down
5 changes: 3 additions & 2 deletions angular-standalone/base/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { enableProdMode, importProvidersFrom } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { RouteReuseStrategy, provideRouter } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { IonicRouteStrategy } from '@ionic/angular/common';
mapsandapps marked this conversation as resolved.
Show resolved Hide resolved
import { provideIonicAngular } from '@ionic/angular/standalone';

import { routes } from './app/app.routes';
import { AppComponent } from './app/app.component';
Expand All @@ -14,7 +15,7 @@ if (environment.production) {
bootstrapApplication(AppComponent, {
providers: [
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
importProvidersFrom(IonicModule.forRoot({})),
provideIonicAngular(),
provideRouter(routes),
],
});
12 changes: 12 additions & 0 deletions angular-standalone/official/blank/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';
import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
standalone: true,
imports: [IonApp, IonRouterOutlet],
})
export class AppComponent {
constructor() {}
}
4 changes: 2 additions & 2 deletions angular-standalone/official/blank/src/app/home/home.page.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';

@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
standalone: true,
imports: [IonicModule],
imports: [IonHeader, IonToolbar, IonTitle, IonContent],
})
export class HomePage {
constructor() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { IonicModule } from '@ionic/angular';

import { AppComponent } from './app.component';

Expand Down
12 changes: 12 additions & 0 deletions angular-standalone/official/list/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from '@angular/core';
import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
standalone: true,
imports: [IonApp, IonRouterOutlet],
})
export class AppComponent {
constructor() {}
}
5 changes: 3 additions & 2 deletions angular-standalone/official/list/src/app/home/home.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';
import { IonicModule, RefresherCustomEvent } from '@ionic/angular';
import { RefresherCustomEvent } from '@ionic/angular';
mapsandapps marked this conversation as resolved.
Show resolved Hide resolved
import { IonHeader, IonToolbar, IonTitle, IonContent, IonRefresher, IonRefresherContent, IonList } from '@ionic/angular/standalone';
import { MessageComponent } from '../message/message.component';

import { DataService, Message } from '../services/data.service';
Expand All @@ -10,7 +11,7 @@ import { DataService, Message } from '../services/data.service';
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
standalone: true,
imports: [IonicModule, CommonModule, MessageComponent],
imports: [CommonModule, IonHeader, IonToolbar, IonTitle, IonContent, IonRefresher, IonRefresherContent, IonList, MessageComponent],
})
export class HomePage {
private data = inject(DataService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { ViewMessagePage } from '../view-message/view-message.page';

import { MessageComponent } from './message.component';
Expand All @@ -11,7 +10,7 @@ describe('MessageComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [MessageComponent, IonicModule, ViewMessagePage],
imports: [MessageComponent, ViewMessagePage],
providers: [provideRouter([])]
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject, Input } from '@angular/core';
import { RouterLink } from '@angular/router';
import { IonicModule, Platform } from '@ionic/angular';
import { Platform } from '@ionic/angular/common';
mapsandapps marked this conversation as resolved.
Show resolved Hide resolved
import { IonItem, IonLabel, IonNote, IonIcon } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { chevronForward } from 'ionicons/icons';
import { Message } from '../services/data.service';

addIcons({ chevronForward });

@Component({
selector: 'app-message',
templateUrl: './message.component.html',
styleUrls: ['./message.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [CommonModule, IonicModule, RouterLink],
imports: [CommonModule, RouterLink, IonItem, IonLabel, IonNote, IonIcon],
})
export class MessageComponent {
private platform = inject(Platform);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { provideRouter } from '@angular/router';

import { ViewMessagePage } from './view-message.page';
Expand All @@ -10,7 +9,7 @@ describe('ViewMessagePage', () => {

beforeEach(async () => {
TestBed.configureTestingModule({
imports: [ViewMessagePage, IonicModule],
imports: [ViewMessagePage],
providers: [provideRouter([])],
}).compileComponents();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { CommonModule } from '@angular/common';
import { Component, inject, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonicModule, Platform } from '@ionic/angular';
import { Platform } from '@ionic/angular/common';
import { IonHeader, IonToolbar, IonButtons, IonBackButton, IonContent, IonItem, IonIcon, IonLabel, IonNote } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { personCircle } from 'ionicons/icons';
import { DataService, Message } from '../services/data.service';

addIcons({ personCircle });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs (step 7) use addIcons in the constructor. Is there a reason it's better in one place over the other? (I'm least-familiar with Angular, and I don't know the answer.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I was following the design doc. I'll switch to follow the Framework docs to stick with consistency.


@Component({
selector: 'app-view-message',
templateUrl: './view-message.page.html',
styleUrls: ['./view-message.page.scss'],
standalone: true,
imports: [IonicModule, CommonModule],
imports: [CommonModule, IonHeader, IonToolbar, IonButtons, IonBackButton, IonContent, IonItem, IonIcon, IonLabel, IonNote],
})
export class ViewMessagePage implements OnInit {
public message!: Message;
Expand Down
9 changes: 7 additions & 2 deletions angular-standalone/official/sidemenu/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { RouterLink, RouterLinkActive } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { IonApp, IonSplitPane, IonMenu, IonContent, IonList, IonListHeader, IonNote, IonMenuToggle, IonItem, IonIcon, IonLabel, IonRouterOutlet } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { mailOutline, mailSharp, paperPlaneOutline, paperPlaneSharp, heartOutline, heartSharp, archiveOutline, archiveSharp, trashOutline, trashSharp, warningOutline, warningSharp, bookmarkOutline, bookmarkSharp } from 'ionicons/icons';

addIcons({ mailOutline, mailSharp, paperPlaneOutline, paperPlaneSharp, heartOutline, heartSharp, archiveOutline, archiveSharp, trashOutline, trashSharp, warningOutline, warningSharp, bookmarkOutline, bookmarkSharp });

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
standalone: true,
imports: [IonicModule, RouterLink, RouterLinkActive, CommonModule],
imports: [RouterLink, RouterLinkActive, CommonModule, IonApp, IonSplitPane, IonMenu, IonContent, IonList, IonListHeader, IonNote, IonMenuToggle, IonItem, IonIcon, IonLabel, IonRouterOutlet],
})
export class AppComponent {
public appPages = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { IonicModule } from '@ionic/angular';

import { FolderPage } from './folder.page';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component, inject, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { IonHeader, IonToolbar, IonButtons, IonMenuButton, IonTitle, IonContent } from '@ionic/angular/standalone';

@Component({
selector: 'app-folder',
templateUrl: './folder.page.html',
styleUrls: ['./folder.page.scss'],
standalone: true,
imports: [IonicModule],
imports: [IonHeader, IonToolbar, IonButtons, IonMenuButton, IonTitle, IonContent],
})
export class FolderPage implements OnInit {
public folder!: string;
Expand Down
10 changes: 3 additions & 7 deletions angular-standalone/official/tabs/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { Component, EnvironmentInjector, inject } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';

@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.scss'],
standalone: true,
imports: [IonicModule, CommonModule],
imports: [IonApp, IonRouterOutlet],
})
export class AppComponent {
public environmentInjector = inject(EnvironmentInjector);

constructor() {}
}
4 changes: 2 additions & 2 deletions angular-standalone/official/tabs/src/app/tab1/tab1.page.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
import { ExploreContainerComponent } from '../explore-container/explore-container.component';

@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss'],
standalone: true,
imports: [IonicModule, ExploreContainerComponent],
imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent],
})
export class Tab1Page {
constructor() {}
Expand Down
4 changes: 2 additions & 2 deletions angular-standalone/official/tabs/src/app/tab2/tab2.page.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
import { ExploreContainerComponent } from '../explore-container/explore-container.component';

@Component({
selector: 'app-tab2',
templateUrl: 'tab2.page.html',
styleUrls: ['tab2.page.scss'],
standalone: true,
imports: [IonicModule, ExploreContainerComponent]
imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent]
})
export class Tab2Page {

Expand Down
4 changes: 2 additions & 2 deletions angular-standalone/official/tabs/src/app/tab3/tab3.page.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
import { ExploreContainerComponent } from '../explore-container/explore-container.component';

@Component({
selector: 'app-tab3',
templateUrl: 'tab3.page.html',
styleUrls: ['tab3.page.scss'],
standalone: true,
imports: [IonicModule, ExploreContainerComponent],
imports: [IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent],
})
export class Tab3Page {
constructor() {}
Expand Down
8 changes: 6 additions & 2 deletions angular-standalone/official/tabs/src/app/tabs/tabs.page.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Component, EnvironmentInjector, inject } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { triangle, ellipse, square } from 'ionicons/icons';

addIcons({ triangle, ellipse, square });

@Component({
selector: 'app-tabs',
templateUrl: 'tabs.page.html',
styleUrls: ['tabs.page.scss'],
standalone: true,
imports: [IonicModule],
imports: [IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel],
})
export class TabsPage {
public environmentInjector = inject(EnvironmentInjector);
Expand Down