Dev Teywa

Dev Teywa

  • NA
  • 250
  • 40.1k

how to avoid display redundancy of result in typescript

Feb 7 2018 10:03 AM
hi,
 
i have problem in each click on the button it returns to me the result I want after the click and show me result after the inputs will be emptied it shows me nothing
 
here is a descriptive picture of the problem
 
 
app.component.ts
  1. import { Component,OnInit } from '@angular/core';  
  2.   
  3.   
  4.   
  5.   
  6. @Component({  
  7.   selector: 'app-root',  
  8.   templateUrl: './app.component.html'  
  9. })  
  10. export class AppComponent   
  11. {  
  12.     firstdate:Date;  
  13.     lastdate:Date;  
  14.     filterdata:any;  
  15.     dateCheck(fDate:Date,lDate:Date)   
  16.     {  
  17.         if(this.projetList && this.projetList.length)  
  18.         {  
  19.             this.projetList.forEach((proj :any) => {  
  20.             if (proj.datedeb >=fDate && proj.datefin<=lDate)  
  21.             {  
  22.                 this.filterdata.push(proj);   
  23.             }  
  24.              
  25.         });  
  26.         }  
  27.         return this.filterdata;    
  28.           
  29.     }  
  30.       
  31.           
  32.       
  33.     projetList:any;  
  34.     constructor()   
  35.     {  
  36.         this.filterdata =[];  
  37.         this.projetList=[  
  38.             {name:"maroua",lastname:"oumlaz",datedeb:"2015-10-10",datefin:"2016-02-02"},  
  39.         {name:"yassine",lastname:"oumlaz",datedeb:"2017-11-23",datefin:"2018-01-01"}  
  40.     ];  
  41.     }  
  42.   
  43.   
  44.   
  45.   ngOnInit()   
  46.   {  
  47.     /*if (this.globals.user === '' || this.globals.user === null)   
  48.     {  
  49.       this.route.navigateByUrl('login/login');  
  50.     }*/  
  51.       
  52.   }  
  53. }  
app.component.html
  1. <html>    
  2. <head>    
  3. <title>Date before current date</title>    
  4.     
  5. </head>    
  6. <body>    
  7. <h2>Check if date is between two dates</h2>    
  8. Enter  first Date(dd/mm/yyyy):    
  9. <input type="date" name="fDate"  #firstdate /><br/>    
  10. Enter  second Date(dd/mm/yyyy):    
  11. <input type="date" name="lDate" #lastdate /><br/>    
  12. <input type="submit" value="Check" (click)="dateCheck(firstdate.value,lastdate.value);" />    
  13.     
  14. <p *ngFor="let pr of filterdata">    
  15. {{pr.name}}    
  16. </p>    
  17. </body>    
  18. </html>

Answers (1)