/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
modules/playground/src/todo/main.ts
76 строк
2 KB
Paul Gschwendtner
build: rework benchmarks and examples in `modules/` to new optimization rule (#61566)
29 май 2025, 21:39
29 май 2025, 21:39
9d7768c
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Component, NgModule} from '@angular/core'; import {BrowserModule, platformBrowser} from '@angular/platform-browser'; import {Store, Todo, TodoFactory} from './app/TodoStore'; @Component({ selector: 'todo-app', viewProviders: [Store, TodoFactory], templateUrl: 'todo.html', standalone: false, }) export class TodoApp { todoEdit: Todo | null = null; constructor( public todoStore: Store<Todo>, public factory: TodoFactory, ) {} enterTodo(inputElement: HTMLInputElement): void { this.addTodo(inputElement.value); inputElement.value = ''; } editTodo(todo: Todo): void { this.todoEdit = todo; } doneEditing($event: KeyboardEvent, todo: Todo): void { const which = $event.which; const target = $event.target as HTMLInputElement; if (which === 13) { todo.title = target.value; this.todoEdit = null; } else if (which === 27) { this.todoEdit = null; target.value = todo.title; } } addTodo(newTitle: string): void { this.todoStore.add(this.factory.create(newTitle, false)); } completeMe(todo: Todo): void { todo.completed = !todo.completed; } deleteMe(todo: Todo): void { this.todoStore.remove(todo); } toggleAll($event: MouseEvent): void { const isComplete = ($event.target as HTMLInputElement).checked; this.todoStore.list.forEach((todo: Todo) => { todo.completed = isComplete; }); } clearCompleted(): void { this.todoStore.removeBy((todo: Todo) => todo.completed); } } @NgModule({declarations: [TodoApp], bootstrap: [TodoApp], imports: [BrowserModule]}) export class ExampleModule {} platformBrowser().bootstrapModule(ExampleModule);