Guest User

Untitled

a guest
Jul 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <div>
  2. <button (click)="start()" >Empezar</button>
  3. <button (click)="lapso()">Lapso</button>
  4. <button (click)="stop()">Parar</button>
  5.  
  6. </div>
  7.  
  8. <div>
  9. <p>{{hora}} : {{minuto}} : {{segundos}}</p>
  10. <p *ngFor="let cole of coleccion">{{cole.hora}} : {{cole.minuto}} : {{cole.segundos}}</p>
  11.  
  12. import {Component} from '@angular/core';
  13.  
  14. @Component ({
  15. selector: 'cronometro',
  16. templateUrl: 'app/app.html'
  17. })
  18.  
  19. export class cronometro{
  20.  
  21. }
  22. </div>
  23.  
  24. import { Component } from '@angular/core';
  25. import {cronometro} from '../app/cronometro';
  26.  
  27. @Component({
  28. selector: 'app-root',
  29. styleUrls: ['./app.component.css'],
  30. templateUrl: './app.html',
  31. directives: [cronometro]
  32.  
  33. })
  34. export class AppComponent {
  35. title = 'app';
  36. //creacion de variables
  37. public hora:number = 0;
  38. public minuto:number = 0;
  39. public segundos:number = 0;
  40.  
  41.  
  42.  
  43. public coleccion: Array<any> = [];
  44. public contador:any;
  45.  
  46.  
  47. constructor(){
  48.  
  49. }
  50.  
  51. start(){
  52. if (this.contador == undefined){
  53.  
  54.  
  55. this.contador=setInterval(()=>{
  56.  
  57. this.segundos += 1;
  58. if(this.segundos == 10){
  59. this.minuto += 1;
  60. this.segundos = 0;
  61. }
  62. if(this.minuto == 10){
  63. this.hora +=1;
  64. this.minuto = 0;
  65. }
  66.  
  67. if(this.hora == 10){
  68. this.hora = 0;
  69. this.minuto = 0;
  70. this.segundos = 0;
  71. }
  72. console.log(this.hora);
  73.  
  74. } , 100);
  75. }
  76. }
  77.  
  78. lapso(){
  79.  
  80. let obj:any ={};
  81. obj.hora = this.hora;
  82. obj.minuto = this.minuto;
  83. obj.segundos = this.segundos;
  84.  
  85. this.coleccion.push(obj);
  86. }
  87.  
  88. stop(){
  89. clearInterval(this.contador);
  90. this.hora = 0;
  91. this.minuto = 0;
  92. this.segundos = 0;
  93. this.contador =null;
  94. }
  95.  
  96. }
  97.  
  98. <h1> Hola mundito!! </h1>
  99. <h2>Cronometro</h2>
  100. <cronometro></cronometro>
  101.  
  102. 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'.
  103. Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.
  104.  
  105. i 「wdm」: Failed to compile.
  106.  
  107. <cronometro [contador]="contador" ></cronometro>
Add Comment
Please, Sign In to add comment