Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div>
- <div>
- <h1>Złote myśli</h1>
- </div>
- <div>
- <input name="input" [(ngModel)]="text">
- <button (click)="addThough()">Dodaj</button>
- </div>
- <div>
- <ul>
- <li *ngFor="let item of thoughts">
- <span>{{item.name}} {{item.date | transformDate}} </span>
- <div class="delete">
- <button (click)="delete(item)">-</button>
- </div>
- </li>
- </ul>
- </div>
- </div>
- ----------------------------------
- import { Component, Pipe, PipeTransform } from '@angular/core';
- import * as moment from 'moment';
- @Component({
- selector: 'app-root',
- templateUrl: './app.component.html',
- styleUrls: ['./app.component.scss']
- })
- export class AppComponent {
- thoughts: Array<Though> = [];
- text:string = '';
- addThough(){
- let newThough = new Though();
- newThough.name=this.text;
- newThough.date = moment();
- this.thoughts.push(newThough);
- this.text='';
- }
- delete(item: Though){
- this.thoughts=this.thoughts.filter(e=>e !== item);
- }
- }
- export class Though{
- name :string;
- date : moment.Moment;
- }
- ----------------------------
- import { Pipe, PipeTransform } from '@angular/core';
- import * as moment from 'moment';
- @Pipe({
- name: 'Date'
- })
- export class TransformDatePipe implements PipeTransform {
- transform(value: moment.Moment) : any {
- return value.calendar();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement