0

I trying to pass data from component to html in specific case :

i have in component method that get a id:

component.ts:

getId(){


this.id = 3; // example, i have in id number 3 (example)

}

component.html:

i have here a link url in iframe

<iframe width="1000" height="1000" src="http://....../watcher/ {{ here i want this.id}}" style="border:0"></iframe>

How i can pass this id in component.html?

4
  • does providing .../watcher/{{ id }} not working? Commented Jun 28, 2021 at 10:16
  • no. i thing i need to add <ng-container> but also not work Commented Jun 28, 2021 at 10:33
  • Make a dynamic src variable in your component.ts itself, and directly use it in the iframe src. Commented Jun 28, 2021 at 10:45
  • @SoumilKhandelwal how ? example please Commented Jun 28, 2021 at 10:57

1 Answer 1

2

in your ts:


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

id = 100; // for instance

  constructor(protected _sanitizer: DomSanitizer) {}

  public getUrl(id: number) {
    const urlSanitazed = `http://http.cat/${id}`; // Your url `http://.../watcher/${id}`;

    return this._sanitizer.bypassSecurityTrustResourceUrl(urlSanitazed);
  }

in html:

<iframe
    width="1000"
    height="1000"
    [src]="getUrl(id)"
    style="border: 0"
  ></iframe>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.