Números primos entre {{rangeBegin}} e {{rangeEnd}}
-
+ @for (prime of (primeRangeList(rangeBegin,rangeEnd) | async); track prime) {
+
{{prime}}
+ }
\ No newline at end of file
diff --git a/src/app/app.component.scss b/src/app/app.component.scss
index 8e1f7de5..a1e23434 100644
--- a/src/app/app.component.scss
+++ b/src/app/app.component.scss
@@ -1,41 +1,48 @@
:host {
- .title {
- text-align: center;
- }
+ .title {
+ text-align: center;
+ }
- .prime-table {
- background-color: darkblue;
- width: 90vw;
- margin-left: auto;
- margin-right: auto;
- margin-top: 10px;
- padding: 3px;
+ .desc {
+ width: 90vw;
+ margin-left: auto;
+ margin-right: auto;
+ margin-top: 10px;
+ padding: 3px;
+ }
+ .prime-table {
+ background-color: darkblue;
+ width: 90vw;
+ margin-left: auto;
+ margin-right: auto;
+ margin-top: 10px;
+ padding: 3px;
- &-title {
- font-size: 30px;
- color: white;
- text-align: center;
- }
+ &-title {
+ font-size: 30px;
+ color: white;
+ text-align: center;
+ }
- &-elements {
- display: flex;
- justify-content: space-between;
- flex-wrap: wrap;
+ &-elements {
+ display: flex;
+ justify-content: space-between;
+ flex-wrap: wrap;
- & > div {
- background-color: rgba($color: white, $alpha: 0.9);
- margin: 3px;
- padding: 10px;
- font-size: 20px;
- }
- }
- }
+ & > div {
+ background-color: rgba($color: white, $alpha: 0.9);
+ margin: 3px;
+ padding: 10px;
+ font-size: 20px;
+ }
+ }
+ }
- .pass {
- border: 3px solid yellowgreen;
- }
+ .pass {
+ border: 3px solid yellowgreen;
+ }
- .fail {
- border: 3px solid red;
- }
+ .fail {
+ border: 3px solid red;
+ }
}
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts
index 6978e8ff..71e5a8cb 100644
--- a/src/app/app.component.spec.ts
+++ b/src/app/app.component.spec.ts
@@ -1,35 +1,29 @@
-import { TestBed, waitForAsync } from '@angular/core/testing';
-import { RouterTestingModule } from '@angular/router/testing';
+import { TestBed } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
- beforeEach(waitForAsync(() => {
- TestBed.configureTestingModule({
- imports: [
- RouterTestingModule
- ],
- declarations: [
- AppComponent
- ],
+ beforeEach(async () => {
+ await TestBed.configureTestingModule({
+ imports: [AppComponent],
}).compileComponents();
- }));
+ });
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
- const app = fixture.debugElement.componentInstance;
+ const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
- it(`should have as title 'primes'`, () => {
+ it(`should have the 'primes' title`, () => {
const fixture = TestBed.createComponent(AppComponent);
- const app = fixture.debugElement.componentInstance;
+ const app = fixture.componentInstance;
expect(app.title).toEqual('primes');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
- const compiled = fixture.debugElement.nativeElement;
- expect(compiled.querySelector('.content span').textContent).toContain('primes app is running!');
+ const compiled = fixture.nativeElement as HTMLElement;
+ expect(compiled.querySelector('.content span')?.textContent).toContain('primes app is running!');
});
});
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index fa2287f1..1311254b 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -3,11 +3,13 @@ import { Component } from '@angular/core';
import { Observable } from 'rxjs';
import { AppService } from './app.service';
+import { AsyncPipe } from '@angular/common';
@Component({
selector: 'app-root',
+ imports: [AsyncPipe],
templateUrl: './app.component.html',
- styleUrls: ['./app.component.scss']
+ styleUrls: ['./app.component.scss'],
})
export class AppComponent {
title = 'Primes';
@@ -17,7 +19,7 @@ export class AppComponent {
randomPrime = 3;
randomPrimeRng = 3;
- constructor(private app: AppService) { }
+ constructor(private app: AppService) {}
public primeRangeList(begin: number, end: number): Observable
{
return this.app.primeRangeList(begin, end);
@@ -27,7 +29,10 @@ export class AppComponent {
return this.app.randomPrimeNumber();
}
- public closestPrime(input: number, asc: boolean): Observable {
+ public closestPrime(
+ input: number,
+ asc: boolean
+ ): Observable {
return this.app.closestPrime(input, asc);
}
diff --git a/src/app/app.config.ts b/src/app/app.config.ts
new file mode 100644
index 00000000..6312600b
--- /dev/null
+++ b/src/app/app.config.ts
@@ -0,0 +1,14 @@
+import {
+ ApplicationConfig,
+ provideExperimentalZonelessChangeDetection,
+} from '@angular/core';
+import { provideRouter } from '@angular/router';
+
+import { routes } from './app.routes';
+
+export const appConfig: ApplicationConfig = {
+ providers: [
+ provideExperimentalZonelessChangeDetection(),
+ provideRouter(routes),
+ ],
+};
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 2c3ba299..5ce7811a 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -1,18 +1,12 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
-import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
- declarations: [
- AppComponent
- ],
- imports: [
- BrowserModule,
- AppRoutingModule
- ],
+ declarations: [AppComponent],
+ imports: [BrowserModule],
providers: [],
- bootstrap: [AppComponent]
+ bootstrap: [AppComponent],
})
-export class AppModule { }
+export class AppModule {}
diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts
new file mode 100644
index 00000000..dc39edb5
--- /dev/null
+++ b/src/app/app.routes.ts
@@ -0,0 +1,3 @@
+import { Routes } from '@angular/router';
+
+export const routes: Routes = [];
diff --git a/src/app/app.service.ts b/src/app/app.service.ts
index 205ebff4..596a308e 100644
--- a/src/app/app.service.ts
+++ b/src/app/app.service.ts
@@ -3,7 +3,7 @@ import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { filter, map } from 'rxjs/operators';
-import { isEven, isOdd, PrimeNumber } from 'primes-rs/pkg/primes';
+import { isEven, isOdd, PrimeNumber } from '../../primes-rs/pkg/primes';
interface Module {
PrimeNumber: typeof PrimeNumber;
@@ -12,14 +12,14 @@ interface Module {
}
@Injectable({
- providedIn: 'root'
+ providedIn: 'root',
})
export class AppService {
- module = new BehaviorSubject(null);
+ module = new BehaviorSubject(null);
constructor() {
const appComp = this;
- import('primes-rs/pkg/primes')
+ import('../../primes-rs/pkg/primes')
.then((mod: Module) => {
appComp.module.next(mod);
})
@@ -34,7 +34,10 @@ export class AppService {
return this.run((mod) => mod.PrimeNumber.nth(input));
}
- public randomPrimeInRange(begin: number, end: number): Observable {
+ public randomPrimeInRange(
+ begin: number,
+ end: number
+ ): Observable {
return this.run((mod) => mod.PrimeNumber.randomRange(begin, end));
}
@@ -42,7 +45,10 @@ export class AppService {
return this.run((mod) => mod.PrimeNumber.random());
}
- public closestPrime(input: number, asc: boolean): Observable {
+ public closestPrime(
+ input: number,
+ asc: boolean
+ ): Observable {
return this.run((mod) => mod.PrimeNumber.closestPrime(input, asc));
}
@@ -64,7 +70,7 @@ export class AppService {
private run(f: (mod: Module) => T): Observable {
return this.module.pipe(
- filter(value => value !== null),
+ filter((value) => value !== null),
map(f)
);
}
diff --git a/src/index.html b/src/index.html
index aeb086d4..c495e76b 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1,5 +1,6 @@
+
Primes
@@ -7,7 +8,9 @@
+
-
+
+