Skip to content

Commit 26a64b5

Browse files
authored
refactor: standalone app and control flow (#151)
1 parent 150f717 commit 26a64b5

File tree

5 files changed

+44
-49
lines changed

5 files changed

+44
-49
lines changed

.browserslistrc

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/app/app.module.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/app/demo-app.component.html

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,31 @@ <h2>Set the SVG style</h2>
2222
<fieldset>
2323
<label>height:</label>
2424
<label>auto <input type="checkbox" [(ngModel)]="autoheight" name="autoheight"></label>
25-
<span class="px" *ngIf="!autoheight"><input type="number" min="0" max="1000" [(ngModel)]="h" name="height"></span>
25+
@if (!autoheight) {
26+
<span class="px"><input type="number" min="0" max="1000" [(ngModel)]="h" name="height"></span>
27+
}
2628
<span style="margin-left:10px;">&nbsp;</span>
2729

2830
<label>width:</label>
2931
<label>auto <input type="checkbox" [(ngModel)]="autowidth" name="autowidth"></label>
30-
<span class="px" *ngIf="!autowidth"><input type="number" min="0" max="1000" [(ngModel)]="w" name="width"></span>
32+
@if (!autowidth) {
33+
<span class="px"><input type="number" min="0" max="1000" [(ngModel)]="w" name="width"></span>
34+
}
3135
</fieldset>
3236
<fieldset>
3337
<label>stretch: <input type="checkbox" [(ngModel)]="stretch" name="stretch"></label>
3438
</fieldset>
3539
</form>
3640

37-
<div *ngIf="display">
38-
<svg-icon [src]="img[onImg]" [stretch]="stretch" [svgStyle]="getNgStyle()"></svg-icon>
41+
@if (display){
42+
<div>
43+
<svg-icon [src]="img[onImg]" [stretch]="stretch" [svgStyle]="getNgStyle()"></svg-icon>
3944

40-
<pre>&lt;svg-icon src="{{img[onImg]}}" [stretch]="{{stretch|json}}"
41-
[svgStyle]="{{getStyle()}}"&gt;
42-
&lt;/svg-icon&gt;</pre>
43-
</div>
45+
<pre>&lt;svg-icon src="{{img[onImg]}}" [stretch]="{{stretch|json}}"
46+
[svgStyle]="{{getStyle()}}"&gt;
47+
&lt;/svg-icon&gt;</pre>
48+
</div>
49+
}
4450

4551
<div>
4652
<button (click)="swapImg()">Swap SVG</button>
@@ -57,8 +63,10 @@ <h2>Set the SVG style</h2>
5763
the document as can be seen by the persistence of the three <svg-icon src="assets/images/eye.svg" [svgStyle]="{ 'width.px': '14'}">
5864
</svg-icon> SVG at the top of the page.</p>
5965

60-
<p *ngIf="!display">Reloading the SVG will cause an http fetch to occur to load the SVG into the registry
61-
where it will persist until programatically unloaded.</p>
66+
@if (!display) {
67+
<p>Reloading the SVG will cause an http fetch to occur to load the SVG into the registry
68+
where it will persist until programmatically unloaded.</p>
69+
}
6270
</div>
6371

6472
<div class="explain">
@@ -80,11 +88,15 @@ <h2>Working with CSS classes</h2>
8088
&lt;/svg-icon&gt;</pre>
8189

8290
<select [(ngModel)]="svgKlass">
83-
<option *ngFor="let c of svgKlasses" [value]="c">{{c}}</option>
91+
@for (c of svgKlasses; track c) {
92+
<option [value]="c">{{c}}</option>
93+
}
8494
</select>
8595

8696
<select [(ngModel)]="klass">
87-
<option *ngFor="let c of klasses" [value]="c">{{c}}</option>
97+
@for (c of klasses; track c) {
98+
<option [value]="c">{{c}}</option>
99+
}
88100
</select>
89101

90102
<button (click)="applied = !applied">{{applied ? 'ignore class' : 'apply class'}}</button>

src/app/demo-app.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Component } from '@angular/core';
22

3-
import { SvgIconRegistryService } from 'angular-svg-icon';
3+
import { SvgIconRegistryService, SvgIconComponent } from 'angular-svg-icon';
4+
import { NgClass, JsonPipe } from '@angular/common';
5+
import { FormsModule } from '@angular/forms';
46

57

68
@Component({
7-
selector: 'app-demo',
8-
styleUrls: [ './demo-app.component.scss' ],
9-
templateUrl: './demo-app.component.html'
9+
standalone: true,
10+
imports: [SvgIconComponent, FormsModule, NgClass, JsonPipe],
11+
selector: 'app-demo',
12+
styleUrls: ['./demo-app.component.scss'],
13+
templateUrl: './demo-app.component.html'
1014
})
1115

1216
export class DemoAppComponent {

src/main.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2-
import { enableProdMode } from '@angular/core';
3-
4-
import { AppModule } from './app/app.module';
1+
import { provideHttpClient } from '@angular/common/http';
2+
import { enableProdMode, importProvidersFrom } from '@angular/core';
3+
import { bootstrapApplication } from '@angular/platform-browser';
4+
import { SvgIconComponent, provideAngularSvgIcon } from 'angular-svg-icon';
5+
import { DemoAppComponent } from './app/demo-app.component';
56

67
enableProdMode();
78

8-
platformBrowserDynamic().bootstrapModule( AppModule );
9+
bootstrapApplication(DemoAppComponent, {
10+
providers: [
11+
importProvidersFrom(SvgIconComponent),
12+
provideAngularSvgIcon(),
13+
provideHttpClient()
14+
]
15+
});

0 commit comments

Comments
 (0)