Advertisement
Guest User

TS

a guest
Apr 2nd, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
  2. import { DataService } from "../data.service";
  3. import { Recipe } from '../logic/Recipe';
  4. import { Router } from '@angular/router';
  5. import { GeolocationService } from '../geolocation.service';
  6. import { FormControl } from '@angular/forms';
  7.  
  8.  
  9. @Component({
  10.   selector: 'app-list',
  11.   templateUrl: './list.component.html',
  12.   styleUrls: ['./list.component.css']
  13. })
  14.  
  15. export class ListComponent implements OnInit {
  16.  
  17.   list: [Recipe]
  18.   @Output() notifyDelete: EventEmitter<number> = new EventEmitter<number>();
  19.  
  20.  
  21.   constructor(private data: DataService,
  22.     private router: Router,
  23.     private geolocation: GeolocationService,
  24.   ) { }
  25.  
  26.   goDetails(recipe: Recipe) {
  27.     this.router.navigate(["/recipe", recipe._id]);
  28.  
  29.   }
  30.  
  31.   goMap(recipe: Recipe) {
  32.     const mapURL = this.geolocation.getMapLink(recipe.location);
  33.     location.href = mapURL;
  34.   }
  35.  
  36.   share(recipe: Recipe) {
  37.     const shareText = `I had this coffee at ${recipe.place} and for me it was ${recipe.rating} stars`;
  38.     if ('share' in navigator) {
  39.       (navigator as any).share({
  40.         title: recipe.name,
  41.         text: shareText,
  42.         url: window.location.href
  43.       }).then(() => console.log("shared")).catch(() => console.log("error sharing"));
  44.     } else {
  45.       const shareURL = `whatsapp://send?text=${encodeURIComponent(shareText)}`;
  46.       location.href = shareURL;
  47.     }
  48.   }
  49.  
  50.   ngOnInit(): void {
  51.     this.data.getList(list => {
  52.       this.list = list;
  53.  
  54.  
  55.     })
  56.   }
  57.  
  58.  
  59.   FormControl = new FormControl('');
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement