Documentos de Académico
Documentos de Profesional
Documentos de Cultura
2021
Maria Alejandra buquete
TO DO LIST
• SIN ESTADO
• los cambios a la lista de tareas pendientes se perderán si la
ventana del navegador se cierra o se vuelve a cargar.
• ng new todo --routing false --style css --skip-git --skip-tests
• ng serve
• http://localhost:4200
• En VS, file/open folder/ toto
TSLINT
• tslint.json
• ./node_modules/.bin/tslint - - init
• Este comando generara el archivo
tslint.json
DATA MODEL
• Para iniciar el modelo de datos para la aplicación, agregar un archivo
llamado
• todoItem.ts (la extensión ts es por typescript)
• en la carpeta todo/src/app
export class TodoItem {
}
task: string;
complete: boolean;
}
• Si aparece un error subrayando export, “not using the local tslint
version found for”, entonces realice lo siguiente:
}
task: string;
complete: boolean;
OPERACIONES DEL TODO LIST
• Agregar un archivo llamado Import { TodoItem } from “./todoItem”;
• todoList.ts export class TodoList {
• en la carpeta todo/src/app
constructor(public user: string, private todoItems: TodoItem[]
= []) {
// nada
}
getItems():readonly TodoItem[] {
return this.todoItems:
}
addItem(task:string){
this.todoItems.push(new TodoItem(task));
}
}
VIEW
• Abrir un archivo llamado {{..}} funciona como un enlace de datos
• app.component.html
• en la carpeta todo/src/app
<h3>
{{ username }}'s To Do List
<h6>{{ itemCount }} Items</h6>
</h3>
BINDING
• Abrir un archivo llamado
• app.component.ts
• en la carpeta todo/src/app
Conceptos Index.html
• Imports
• Decorator
• Class
Guardar
Estilos de HTML
• Hasta ahora generamos contenido con texto plano
• Agreguemos el framework BOOTSTRAP para darle
estilo a nuestra app
• Ejecutar
• Npm install bootstrap@4.4.6
• Ng serve --open
• Agregar una entrada en el archivo angular.json para
que el browser interprete los stilos de Bootstrap
• "node_modules/bootstrap/dist/css/bootstrap.min.css“
• Angular.json es usado para configurar las herramientas del
Proyecto
• LINEAS 34 Y 95
Estilos de HTML
• He agregado los elementos de la plantilla a las clases que
cambiarán su apariencia.
• app.component.html
• Ejecutar
• ng serve
Tareas para completar el TODO LIST
• Displaying the List of To-Do Items
• Creating a Two-Way Data Binding
• Filtering To-Do Items
• Adding To-Do Items
• Displaying Completed To-Do Items
import { Component } from '@angular/core';
import { TodoList } from "./todoList";
import { TodoItem } from "./todoItem";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
Mostrando la Lista styleUrls: ['./app.component.css']
})
de To-Do Items export class AppComponent {
private list = new TodoList("Bob", [
app.component.ts new TodoItem("Go for run"),
new TodoItem("Get flowers"),
new TodoItem("Collect tickets"),
]);
get username(): string {
return this.list.user;
}
get itemCount(): number {
return this.list.items.filter(item => !item.complete).length;
}
get items(): readonly TodoItem[] {
return this.list.items;
}
}
<h3 class="bg-primary text-center text-white p-2">
{{ username }}'s To Do List
<h6 class="mt-1">{{ itemCount }} Incomplete Items</h6>
</h3>
<table class="table table-striped table-bordered table-sm">
<thead>
Mostrando la Lista <tr><th>#</th><th>Description</th><th>Done</th></tr>
</thead>
de To-Do Items <tbody>
<tr *ngFor="let item of items; let i = index">
app.component.html <td>{{ i + 1 }}</td>
<td>{{ item.task }}</td>
<td [ngSwitch]="item.complete">
<span *ngSwitchCase="true">Yes</span>
<span *ngSwitchDefault>No</span>
</td>
</tr>
</tbody>
</table>
Creando un Two-Way Data Binding
<td [ngSwitch]="item.complete">
<span *ngSwitchCase="true">Yes</span>
<span *ngSwitchDefault>No</span>
</td>
</tr>
</tbody>
</table>
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from ‘@angular/forms’;
Mostrando la Lista
import { AppComponent } from './app.component';
de To-Do Items @NgModule({
app.module.ts declarations: [
AppComponent
habilitando la ],
imports: [
caracteristica de BrowserModule, FormsModule
],
two way binding providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Ejecutar
ng serve
Modificar un valor con un CHECKBOX
import { Component } from '@angular/core';
import { TodoList } from "./todoList";
import { TodoItem } from "./todoItem";