Skip to content

Commit

Permalink
Basicos de Angular
Browse files Browse the repository at this point in the history
  • Loading branch information
jtristante committed May 26, 2021
1 parent 8938567 commit 13107cb
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 546 deletions.
511 changes: 3 additions & 508 deletions src/app/app.component.html

Large diffs are not rendered by default.

31 changes: 0 additions & 31 deletions src/app/app.component.spec.ts

This file was deleted.

11 changes: 7 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
selector:'app-root',
templateUrl:'app.component.html'
//template: "<span>Javier</span>"

})
export class AppComponent {
title = 'bases';



}
10 changes: 8 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

import { HeroesModule } from './heroes/heroes.module';
import { ContadorModule } from './contador/contador.module';


@NgModule({
declarations: [
AppComponent
AppComponent,
],
imports: [
BrowserModule
BrowserModule,
HeroesModule,
ContadorModule
],
providers: [],
bootstrap: [AppComponent]
Expand Down
15 changes: 15 additions & 0 deletions src/app/contador/contador.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ContadorComponent } from './contador/contador.component';

@NgModule({
declarations:[
ContadorComponent
],
exports:[
ContadorComponent
]
})


export class ContadorModule{}
24 changes: 24 additions & 0 deletions src/app/contador/contador/contador.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Component} from '@angular/core'

@Component({
selector: 'app-contador',
template: `
<h1>Hola Mundo {{titulo}}</h1>
<h3>La base es: <strong>{{base}}</strong></h3>
<button (click)="acumular(base)" > + {{base}} </button>
<span>{{numero}}</span>
<button (click)="acumular(-base)"> - {{base}} </button>
`
}
)
export class ContadorComponent{

titulo: string = 'Contador App';
numero: number = 10;
base : number = 5;

acumular (valor: number ){
this.numero += valor;
}
}
20 changes: 20 additions & 0 deletions src/app/heroes/heroe/heroe.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h1>{{nombre}}</h1>

<dl>
<td>Nombre: </td>
<dd>{{nombre}}</dd>

<td>Edad: </td>
<dd>{{edad}}</dd>

<td>Función: </td>
<dd>{{obtenerNombre()}}</dd>

<td>En mayusculas: </td>
<dd>{{nombreMayusculas}}</dd>

</dl>

<button (click)="cambiarNombre()">Cambiar Heroe</button>

<button (click)=cambiarEdad()>Cambiar Edad</button>
30 changes: 30 additions & 0 deletions src/app/heroes/heroe/heroe.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

import { Component } from "@angular/core";

@Component( {
selector: 'app-heroe',
templateUrl: 'heroe.component.html'
})
export class HeroeComponent{
nombre: string ='Ironman';
edad: number = 54;

get nombreMayusculas(): string{
return this.nombre.toUpperCase();
}

obtenerNombre():string {
return `${this.nombre} - ${this.edad}`;
}

cambiarNombre(): void {
this.nombre = 'Spiderman';
}

cambiarEdad():void {
this.edad = 30;
}



}
19 changes: 19 additions & 0 deletions src/app/heroes/heroes.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { HeroeComponent } from './heroe/heroe.component';
import { ListadoComponent } from './listado/listado.component';

@NgModule({
declarations:[
HeroeComponent,
ListadoComponent
],
exports:[
ListadoComponent
],
imports:[
CommonModule
]
})

export class HeroesModule{}
21 changes: 21 additions & 0 deletions src/app/heroes/listado/listado.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>listado de Heroes !</h1>

<div *ngIf="heroeBorrado; else noBorrado">
<h3>Heroe Borrado <small>{{heroeBorrado}}</small></h3>
</div>

<ng-template #noBorrado>
<h3>No ha borrado nada</h3>
</ng-template>


<button (click)="borrarHeroe()">
Borrar
</button>

<ul>
<li *ngFor="let heroe of heroes; let i = index">
{{i+1}} {{heroe}}
</li>
</ul>

20 changes: 20 additions & 0 deletions src/app/heroes/listado/listado.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component} from '@angular/core';


@Component({
selector: 'app-listado',
templateUrl: './listado.component.html',
})
export class ListadoComponent {

heroes : string [] = ['Spiderman', 'Sperman' , 'hulky', 'PepePerez', 'juan'];
heroeBorrado:string ='';

borrarHeroe(){
console.log('borrando...');
this.heroeBorrado = this.heroes.shift() || '';

}


}
41 changes: 40 additions & 1 deletion src/styles.css
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
/* You can add global styles to this file, and also import other style files */
* {
font-family: Helvetica, Arial, sans-serif;
font-weight: 200;
}

html, body {

background: white;
margin: 20px;
color: #3e4144;
-webkit-font-smoothing: antialiased;
}


dd {
font-weight: bold;
}

button {
background-color: black;
border-radius: 5px;
border: 0px;
color: white;
cursor: pointer;
margin-right: 5px;
margin-left: 5px;
padding: 5px 10px;
}

button:hover {
background-color: #3e4144;
}

button:focus{
outline: none;
}

.p-1 {
padding: 1px;
}

0 comments on commit 13107cb

Please sign in to comment.