From 31eaa4e61bbb9eeafbb5ba656cef24786651fa8c Mon Sep 17 00:00:00 2001 From: John kirathe Date: Fri, 14 Jun 2024 00:18:11 +0300 Subject: [PATCH] Update signal.ts --- dev/signal.ts | 53 --------------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/dev/signal.ts b/dev/signal.ts index c4155e3..8b13789 100644 --- a/dev/signal.ts +++ b/dev/signal.ts @@ -1,54 +1 @@ -import { Component, computed, OnInit, signal } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; -import { UploadComponent } from './components/upload/upload.component'; - -interface User { - id: number; - name: string; - email: string; -} -@Component({ - selector: 'app-root', - standalone: true, - imports: [RouterOutlet, UploadComponent], - templateUrl: './app.component.html', - styleUrl: './app.component.scss', -}) -export class AppComponent implements OnInit { - title = 'drag-drop-upload-app'; - private users = signal([]); - userCount = computed(() => this.users().length); - - ngOnInit(): void { - this.users.set([{ id: 1, name: 'john', email: 'john@mail.com' }]); - - this.users.update((users: User[]) => [ - ...users, - { id: 2, name: 'john2', email: 'john2@mail.com' },{ id: 3, name: 'john', email: 'john@mail.com' } - ]); - - this.users.update((users: User[]) => - users.map((user) => { - if (user.id === 1) { - user.email = 'j@mail.com'; - } - return user; - }) - ); - - console.log('userCount: ', this.userCount()); - - const showCount = signal(true); - const count = signal(10); - const conditionalCount = computed(() => { - if (showCount()) { - return `The count is ${count()}.`; - } else { - return 'Nothing to see here!'; - } - }); - - console.log('conditionalCount: ', conditionalCount()); - } -}