Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1.  
  2. <div>
  3.  
  4. <div>
  5. <h1>Złote myśli</h1>
  6. </div>
  7.  
  8.  
  9. <div>
  10. <input name="input" [(ngModel)]="text">
  11. <button (click)="addThough()">Dodaj</button>
  12. </div>
  13.  
  14. <div>
  15. <ul>
  16. <li *ngFor="let item of thoughts">
  17. <span>{{item.name}} {{item.date | transformDate}} </span>
  18.  
  19. <div class="delete">
  20. <button (click)="delete(item)">-</button>
  21. </div>
  22. </li>
  23. </ul>
  24. </div>
  25.  
  26. </div>
  27. ----------------------------------
  28. import { Component, Pipe, PipeTransform } from '@angular/core';
  29. import * as moment from 'moment';
  30.  
  31. @Component({
  32. selector: 'app-root',
  33. templateUrl: './app.component.html',
  34. styleUrls: ['./app.component.scss']
  35. })
  36. export class AppComponent {
  37.  
  38. thoughts: Array<Though> = [];
  39. text:string = '';
  40.  
  41.  
  42. addThough(){
  43. let newThough = new Though();
  44. newThough.name=this.text;
  45. newThough.date = moment();
  46.  
  47. this.thoughts.push(newThough);
  48. this.text='';
  49. }
  50.  
  51. delete(item: Though){
  52. this.thoughts=this.thoughts.filter(e=>e !== item);
  53.  
  54. }
  55.  
  56. }
  57.  
  58. export class Though{
  59. name :string;
  60. date : moment.Moment;
  61. }
  62.  
  63.  
  64. ----------------------------
  65. import { Pipe, PipeTransform } from '@angular/core';
  66. import * as moment from 'moment';
  67.  
  68. @Pipe({
  69. name: 'Date'
  70. })
  71. export class TransformDatePipe implements PipeTransform {
  72.  
  73. transform(value: moment.Moment) : any {
  74. return value.calendar();
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement