Guest User

Untitled

a guest
Jun 24th, 2018
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. import { Directive, Input, OnInit } from '@angular/core';
  2. import {GoogleMapsAPIWrapper} from '@agm/core';
  3.  
  4. declare let google: any;
  5. @Directive({
  6. // tslint:disable-next-line:directive-selector
  7. selector: 'appCycleDirection'
  8. })
  9. export class CycleDirectionDirective implements OnInit {
  10.  
  11. @Input() org;
  12. @Input() dst;
  13. @Input() originPlaceId: any;
  14. @Input() destinationPlaceId: any;
  15. @Input() waypoints: any;
  16. @Input() directionsDisplay: any;
  17. @Input() estimatedTime: any;
  18. @Input() estimatedDistance: any;
  19. constructor(private gmapsApi: GoogleMapsAPIWrapper) { }
  20.  
  21. ngOnInit() {
  22. console.log(' In directive ');
  23. console.log(this.org);
  24. this.gmapsApi.getNativeMap().then(map => {
  25. const directionsService = new google.maps.DirectionsService;
  26. const directionsDisplay = new google.maps.DirectionsRenderer;
  27. directionsDisplay.setMap(map);
  28. directionsService.route({
  29. origin: {lat: this.org.latitude, lng: this.org.longitude},
  30. destination: {lat: this.dst.latitude, lng: this.dst.longitude},
  31. waypoints: [],
  32. optimizeWaypoints: true,
  33. travelMode: 'TRANSIT'
  34. }, function(response, status) {
  35. if (status === 'OK') {
  36. directionsDisplay.setDirections(response);
  37. console.log(response);
  38. } else {
  39. window.alert('Directions request failed due to ' + status);
  40. }
  41. });
  42.  
  43. });
  44. }
  45. }
  46.  
  47. <agm-map *ngIf="Address !== undefined" [latitude]="lat" [longitude]="lng" [zoom]="zoom">
  48. <appCycleDirection *ngIf="dst !== undefined" [org]="org" [dst]="dst"></appCycleDirection>
  49. <agm-marker [style.height.px]="map.offsetHeight" [latitude]="lat" [longitude]="lng"></agm-marker>
  50. </agm-map>
  51.  
  52. > Uncaught (in promise): Error: Template parse errors: Can't bind to
  53. > 'org' since it isn't a known property of 'appCycleDirection'.
  54. > ("[latitude]="lat" [longitude]="lng" [zoom]="zoom">
  55. > <appCycleDirection *ngIf="dst !== undefined" [ERROR ->][org]="org" [dst]="dst"></appCycleDirection>
  56. > <agm-marker [style.height.px]="map.offsetHeight" ["): ng:///LayoutModule/FindCycleComponent.html@9:50 Can't bind to 'dst'
  57. > since it isn't a known property of 'appCycleDirection'. ("lat"
  58. > [longitude]="lng" [zoom]="zoom">
  59. > <appCycleDirection *ngIf="dst !== undefined" [org]="org" [ERROR ->][dst]="dst"></appCycleDirection>
  60. > <agm-marker [style.height.px]="map.offsetHeight" [latitude]="l"): ng:///LayoutModule/FindCycleComponent.html@9:62
  61. > 'appCycleDirection' is not a known element:
  62. > 1. If 'appCycleDirection' is an Angular component, then verify that it is part of this module.
  63. > 2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("> <agm-map
  64. > *ngIf="cycleAddress !== undefined" [latitude]="lat" [longitude]="lng" [zoom]="zoom">
  65. > [ERROR ->]<appCycleDirection *ngIf="dst !== undefined" [org]="org" [dst]="dst"></appCycleDirection>
  66. > <agm-m"): ng:///LayoutModule/FindCycleComponent.html@9:4
Add Comment
Please, Sign In to add comment