1

Blockquote

how to set the parameter in the URL?

My code as TS below

import { KlassaktUserService,KlassaktStorageService, KlassaktApiService } from '../../core';
import { KlassaktDashboardService, Student, listData } from '../../core/api/dashboard.sevice';
import { DomSanitizer, SafeResourceUrl, SafeUrl} from '@angular/platform-browser';

declare var $: any;
@Component({ 
  selector: 'klassakt-photos',
  templateUrl: './photos.component.html' 
})
export class KlassaktPhotosComponent extends KlassaktDashboardComponent implements OnInit {
  }
  public loaderService: KlassaktLoaderService;

  async ngOnInit() {
    await super.ngOnInit();
  }
  public constructor(

    protected _dashboardService: KlassaktDashboardService,
    public _sanitizer: DomSanitizer) {      
    let  selectedStudent = {
      schoolId: "134"
    }
    this.src = this.sanitizer.bypassSecurityTrustResourceUrl(`http://designs.mydeievents.com/jq-3d-flip-book/index.html?id=${selectedStudent.schoolId}`)
  }
  }
  public get students(): Student[]
  {
    return this._dashboardService.account.students;
  } 
}

this is my parameter which is found in the component.html file.

<p>Hi Arjun this is school Id {{selectedStudent.schoolId}}</p>

from ts file, I want to pass the same parameter 134 is my static school id

 schoolId: "134"

if I want to set dynamic parameter the code is below but not getting "param"

 param : number = this.selectedStudent.schoolId;

But i am not getting static or dynamic parameter in my project.

If I am using the below code working fine.

@Input()
      url: string = "https://arjunwalmiki.blogspot.com/";
      urlSafe: SafeResourceUrl;
     this.urlSafe = this._sanitizer.bypassSecurityTrustResourceUrl(this.url);

    <iframe width="200px" height="300px" frameBorder="0" [src]="urlSafe"></iframe>

above code is working because of its parameterless call with a parameter not working.

Laczkó Örs
  • 1,082
  • 1
  • 18
  • 38
Arjun Walmiki
  • 173
  • 1
  • 1
  • 13

4 Answers4

1

Maybe this works:

<iframe [src]="'http://designs.mydeievents.com/jq-3d-flip-book/index.html?id='+selectedStudent.schoolId"></iframe>
Ehsan Kiani
  • 3,050
  • 1
  • 17
  • 19
0

Try like this:

TS:

import { DomSanitizer} from '@angular/platform-browser';

  constructor(private sanitizer: DomSanitizer) {

   let  selectedStudent = {
      schoolId: "101"
    }
    this.src = this.sanitizer.bypassSecurityTrustResourceUrl(`http://designs.mydeievents.com/jq-3d-flip-book/index.html?id=${selectedStudent.schoolId}`)
  }

HTML

<iframe [src]="src"></iframe>

Stackbiltz Demo

Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
0

Angular will sanitise the iframe url for you so you can't easily inject javascript into it, this is to protect you from XSS. There are workarounds in the following question.

How to set iframe src in Angular 2 without causing `unsafe value` exception?

Sam
  • 1,736
  • 8
  • 15
-1

This is my code after mix typescript ,jquery and html i found the solution.

 <a (click)="showDiv(selectedStudent.schoolId)" data-toggle="modal" data-target="#exampleModal"> Arjun click here </a>


<!-- Modal -->

 <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                <!--<iframe id="myIframe" onload="delayedLoad()"></iframe>-->
                <div id="videoContainer">
                </div>
              </div>
              <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

              </div>
            </div>
          </div>
        </div>
showDiv(pageid) {

    this.autoPlayVideo(pageid)
  }

  autoPlayVideo(vcode) {
    $("#videoContainer").html('<iframe width="200px" height="200px" src="http://designs.mydeievents.com/jq-3d-flip-book/index.html?id=' + vcode + '" ></iframe>');
    };

Thank you to all for your valuable time .spl thanks to @Adrita Sharma.

Arjun Walmiki
  • 173
  • 1
  • 1
  • 13