From a76881a140ecb5514ff042f4bdf9fd03f6c3b249 Mon Sep 17 00:00:00 2001 From: HarveyChou Date: Fri, 4 Nov 2022 14:11:35 +0800 Subject: [PATCH] =?UTF-8?q?ngIf=20=E8=B7=9F=20else=20=E5=AF=A6=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.component.html | 15 ++++++++++----- src/app/app.component.spec.ts | 35 ----------------------------------- src/app/app.component.ts | 31 ++++++++++++++++--------------- 3 files changed, 26 insertions(+), 55 deletions(-) delete mode 100644 src/app/app.component.spec.ts diff --git a/src/app/app.component.html b/src/app/app.component.html index 437fe71..0113d22 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,5 +1,10 @@ - - + + + +
+ +
+ + +
無待辦事項
+
diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts deleted file mode 100644 index 6c98b2e..0000000 --- a/src/app/app.component.spec.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; -import { AppComponent } from './app.component'; - -describe('AppComponent', () => { - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [ - RouterTestingModule - ], - declarations: [ - AppComponent - ], - }).compileComponents(); - }); - - it('should create the app', () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app).toBeTruthy(); - }); - - it(`should have as title 'Learn'`, () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('Learn'); - }); - - it('should render title', () => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('.content span')?.textContent).toContain('Learn app is running!'); - }); -}); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fe3ea8e..816cc2f 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,28 +1,29 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Task } from './task'; @Component({ selector: 'my-app', templateUrl: './app.component.html', - styleUrls: [ './app.component.css' ] + styleUrls: ['./app.component.css'], }) -export class AppComponent { - tasks: Task[] = [ - new Task({ TaskSn: '001', TaskName: '待辦事項 A', State: 'Finish' }), - new Task({ TaskSn: '002', TaskName: '待辦事項 B', State: 'Doing' }), - new Task({ TaskSn: '003', TaskName: '待辦事項 C', State: 'None' }), - new Task({ TaskSn: '004', TaskName: '待辦事項 D', State: 'None' }), - ]; - trackByItems(index:number, task:Task):string{ - return task.TaskSn; +export class AppComponent implements OnInit { + tasks!: Task[]; + + ngOnInit(): void { + this.onLoad(); } - onReset():void{ - this.tasks=[ + + onLoad(): void { + this.tasks = [ new Task({ TaskSn: '001', TaskName: '待辦事項 A', State: 'Finish' }), new Task({ TaskSn: '002', TaskName: '待辦事項 B', State: 'Doing' }), - new Task({ TaskSn: '004', TaskName: '待辦事項 C', State: 'None' }), - new Task({ TaskSn: '005', TaskName: '待辦事項 D', State: 'None' }), + new Task({ TaskSn: '003', TaskName: '待辦事項 C', State: 'None' }), + new Task({ TaskSn: '004', TaskName: '待辦事項 D', State: 'None' }), ]; } + + onClear(): void { + this.tasks = []; + } }