Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div>
- <button (click)="start()" >Empezar</button>
- <button (click)="lapso()">Lapso</button>
- <button (click)="stop()">Parar</button>
- </div>
- <div>
- <p>{{hora}} : {{minuto}} : {{segundos}}</p>
- <p *ngFor="let cole of coleccion">{{cole.hora}} : {{cole.minuto}} : {{cole.segundos}}</p>
- import {Component} from '@angular/core';
- @Component ({
- selector: 'cronometro',
- templateUrl: 'app/app.html'
- })
- export class cronometro{
- }
- </div>
- import { Component } from '@angular/core';
- import {cronometro} from '../app/cronometro';
- @Component({
- selector: 'app-root',
- styleUrls: ['./app.component.css'],
- templateUrl: './app.html',
- directives: [cronometro]
- })
- export class AppComponent {
- title = 'app';
- //creacion de variables
- public hora:number = 0;
- public minuto:number = 0;
- public segundos:number = 0;
- public coleccion: Array<any> = [];
- public contador:any;
- constructor(){
- }
- start(){
- if (this.contador == undefined){
- this.contador=setInterval(()=>{
- this.segundos += 1;
- if(this.segundos == 10){
- this.minuto += 1;
- this.segundos = 0;
- }
- if(this.minuto == 10){
- this.hora +=1;
- this.minuto = 0;
- }
- if(this.hora == 10){
- this.hora = 0;
- this.minuto = 0;
- this.segundos = 0;
- }
- console.log(this.hora);
- } , 100);
- }
- }
- lapso(){
- let obj:any ={};
- obj.hora = this.hora;
- obj.minuto = this.minuto;
- obj.segundos = this.segundos;
- this.coleccion.push(obj);
- }
- stop(){
- clearInterval(this.contador);
- this.hora = 0;
- this.minuto = 0;
- this.segundos = 0;
- this.contador =null;
- }
- }
- <h1> Hola mundito!! </h1>
- <h2>Cronometro</h2>
- <cronometro></cronometro>
- ERROR in src/app/app.component.ts(8,3): error TS2345: Argument of type '{ selector: string; styleUrls: string[]; templateUrl: string; directives: (typeof cronometro)[]; }' is not assignable to parameter of type 'Component'.
- Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.
- i 「wdm」: Failed to compile.
- <cronometro [contador]="contador" ></cronometro>
Add Comment
Please, Sign In to add comment