Skip to content

Commit

Permalink
feat(angular): use Ionic standalone components (#1798)
Browse files Browse the repository at this point in the history
  • Loading branch information
thetaPC authored Oct 12, 2023
1 parent 4fa4327 commit 06abacb
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 52 deletions.
10 changes: 0 additions & 10 deletions angular-standalone/base/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*.svg",
"input": "node_modules/ionicons/dist/ionicons/svg",
"output": "./svg"
}
],
"styles": ["src/theme/variables.scss", "src/global.scss"],
Expand Down Expand Up @@ -109,11 +104,6 @@
"glob": "**/*",
"input": "src/assets",
"output": "assets"
},
{
"glob": "**/*.svg",
"input": "node_modules/ionicons/dist/ionicons/svg",
"output": "./svg"
}
],
"styles": ["src/theme/variables.scss", "src/global.scss"],
Expand Down
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.5.0",
"ionicons": "^7.2.1",
"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
4 changes: 2 additions & 2 deletions angular-standalone/base/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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, provideIonicAngular } from '@ionic/angular/standalone';

import { routes } from './app/app.routes';
import { AppComponent } from './app/app.component';
Expand All @@ -14,7 +14,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() {}
}
4 changes: 2 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,6 @@
import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';
import { IonicModule, RefresherCustomEvent } from '@ionic/angular';
import { RefresherCustomEvent, 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 +10,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,7 +1,9 @@
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, IonItem, IonLabel, IonNote, IonIcon } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { chevronForward } from 'ionicons/icons';
import { Message } from '../services/data.service';

@Component({
Expand All @@ -10,12 +12,15 @@ import { Message } from '../services/data.service';
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);
@Input() message?: Message;
isIos() {
return this.platform.is('ios')
}
constructor() {
addIcons({ chevronForward });
}
}
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,23 +1,27 @@
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, 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';

@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;
private data = inject(DataService);
private activatedRoute = inject(ActivatedRoute);
private platform = inject(Platform);

constructor() {}
constructor() {
addIcons({ personCircle });
}

ngOnInit() {
const id = this.activatedRoute.snapshot.paramMap.get('id') as string;
Expand Down
11 changes: 8 additions & 3 deletions angular-standalone/official/sidemenu/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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';

@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 All @@ -19,5 +22,7 @@ export class AppComponent {
{ title: 'Spam', url: '/folder/spam', icon: 'warning' },
];
public labels = ['Family', 'Friends', 'Notes', 'Work', 'Travel', 'Reminders'];
constructor() {}
constructor() {
addIcons({ mailOutline, mailSharp, paperPlaneOutline, paperPlaneSharp, heartOutline, heartSharp, archiveOutline, archiveSharp, trashOutline, trashSharp, warningOutline, warningSharp, bookmarkOutline, bookmarkSharp });
}
}
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
10 changes: 7 additions & 3 deletions angular-standalone/official/tabs/src/app/tabs/tabs.page.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
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';

@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);

constructor() {}
constructor() {
addIcons({ triangle, ellipse, square });
}
}

0 comments on commit 06abacb

Please sign in to comment.