Угловой - невозможно перенаправить на другой компонент с помощью нажатия на пин-код карты Bing - PullRequest
0 голосов
/ 06 мая 2018

Bing Map Push pin нажата, но Маршрутизатор становится неопределенным в журнале консоли.

, поэтому невозможно перенаправить. Если я добавил router.navigate в конструктор, он работает отлично.

Ниже мой код

 import { Component,  ViewChild, OnInit } from '@angular/core';
    import { } from "bingmaps/scripts/MicrosoftMaps/Microsoft.Maps.All"
    import {Router,ActivatedRoute} from '@angular/router';

        @Component({
          selector: 'device-map',
          templateUrl: './device-map.component.html'  
        })
         
        export class DeviceMapComponent implements OnInit{
          @ViewChild('myMap') myMap;
          
          constructor(public router: Router,  public route: ActivatedRoute,) {
            console.log(this.router); }

          pushpinClicked(e){
            console.log("I am clicked");
            console.log(this.router);
            this.router.navigate(['/Dashboard'], { queryParams: { deviceId: 
             e.target.metadata.title } }); } 

            ngOnInit(){              
            var map = new Microsoft.Maps.Map(this.myMap.nativeElement, {
                credentials: 'My key', center: new Microsoft.Maps.Location(47.6149, -122.1941)
            });

              var infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
                title: "Microsoft", description: "City Center", visible: false,
            });

            infobox.setMap(map);
            var randomLocation = Microsoft.Maps.TestDataGenerator.getLocations(1, map.getBounds());
            var pin = new Microsoft.Maps.Pushpin(map.getCenter(),  {  title: 'Microsoft' });
            pin.metadata = { title: 'Device 1',  description: 'Pin discription' };
            Microsoft.Maps.Events.addHandler(pin, 'click', this.pushpinClicked);
            map.entities.push(pin);
          } 
        }

1 Ответ

0 голосов
/ 08 мая 2018

Ниже приведен способ добавления навигации для нажатия кнопки (карта Bing). Требуется функция стрелки.

Microsoft.Maps.Events.addHandler(pin, 'click',  () => {
 this.router.navigateByUrl('/dashboard');});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...