old-moya.component.ts 1.37 KB

import {map} from 'rxjs/operators';
import { Component, OnInit,  ViewChild, ElementRef } from '@angular/core';
import {Location, LocationStrategy, HashLocationStrategy, PathLocationStrategy} from '@angular/common';
import {NavigationExtras, ActivatedRoute, Router} from '@angular/router';

@Component({
  selector: 'moya-old',
  providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}],
  templateUrl: './old-moya.component.html',
  styleUrls: ['./old-moya.component.scss']
})
export class OldMoyaComponent implements OnInit {


  frameUrl: String = '/MoyaWeb/';



  @ViewChild('iframe') iframe: any;
  height = '700px';



  constructor(private location: Location, private route: ActivatedRoute) {

    route.queryParamMap.pipe(map(a => a.get('p'))).subscribe(x => {
      console.log(x);
      if (x) {
        this.frameUrl = '/MoyaWeb/' + x.replace('::', '?');
      }
    });
  }


  ngOnInit() { }

  changeUrl() {
    const tmpFrameUrl = this.iframe.nativeElement.contentWindow.location.href.split('/MoyaWeb/', 2);

    if (tmpFrameUrl.length > 1) {
      this.location.replaceState(this.location.path(false).split('?', 1)[0] + '?p=' + tmpFrameUrl[1].replace('?', '::') );
    }


    console.log(this.iframe.nativeElement.contentWindow.document.body.height);

    this.height = (this.iframe.nativeElement.contentWindow.document.body.scrollHeight + 50) + 'px';




  }

}