ionic3 /角度domsanitizer

时间:2018-08-30 09:32:28

标签: angular typescript ionic-framework ionic3

我正在向ionic3应用程序添加DOM Sanitizer。因为我想嵌入google map,但是说DomSanitizer未定义。我已经尝试了很多关于stackoverflow的示例,但是仍然没有运气。

我的track.ts代码:

import {Component} from '@angular/core';
import {DataProvider} from '../../providers/data/data';
import { DomSanitizer, SafeResourceUrl, SafeUrl} from '@angular/platform-browser';

@Component({
  selector: 'page-track',
  templateUrl: 'track.html',
})

export class TrackPage {

  track: any;
  user: any;
  map: GoogleMap;
  marker: any;
  timer: any;
  initialized = false;

  constructor(public _data: DataProvider) {}
  constructor(private sanitizer: DomSanitizer) {}


  ngOnInit() {
    this.map = null;
    this.marker = null;
    this.initialized = false;
    this.checkForTrackingAvailability();
  }

    //this.sanitizer = sanitizer;
  checkForTrackingAvailability() {
    this._data.get('trackgps').subscribe((res: any) => {
      if (res && res.response === 200 && res.data) {
        this.track = Object.assign({}, res.data);
        this.loadMap();
      } else {
        this.track = null;
      }
      this.initialized = true;
    });
  }

  loadMap() {
    const latLng = {lat: this.track.latitude, lng: this.track.longitude};
    var lat = this.track.latitude;
    var lng = this.track.longitude;
    console.log(this.sanitizer);

    return this.sanitizer.bypassSecurityTrustResourceUrl("//www.google.com/maps/embed/v1/place?q="+lat+","+lng+"&key=MY_API_KEY");

  }


  ngOnDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  }
}

运行此代码后,输出如下。我不知道怎么了控制台还说this.sanitize未定义。

enter image description here

0 个答案:

没有答案