Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在TypeScript中从iFrame调用函数_Angular_Iframe - Fatal编程技术网

Angular 在TypeScript中从iFrame调用函数

Angular 在TypeScript中从iFrame调用函数,angular,iframe,Angular,Iframe,我正在使用Angular 5,而且对打字脚本和Angular还比较陌生。单击后,我知道如何从我的x.component.html中的常规按钮调用函数,但找不到如何从iFrame调用函数 My component.html代码:- 我认为您的控制台中也存在关于不安全url值的错误。这是angular中的默认安全过程。你必须用消毒液绕过它。 此外,您还需要检查您请求的域是否允许您使用X-Frame选项显示iframe: 在您的component.ts中 import { DomSanitizer,

我正在使用Angular 5,而且对打字脚本和Angular还比较陌生。单击后,我知道如何从我的x.component.html中的常规按钮调用函数,但找不到如何从iFrame调用函数

My component.html代码:-


我认为您的控制台中也存在关于不安全url值的错误。这是angular中的默认安全过程。你必须用消毒液绕过它。 此外,您还需要检查您请求的域是否允许您使用X-Frame选项显示iframe:

在您的component.ts中

import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
export class AppComponent {
  constructor(private sanitizer: DomSanitizer)
      {
         this.setSafeUrl();
      }
  safeUrl: SafeResourceUrl;
  setSafeUrl(){
     var nd = new Date(); 
     var Day = nd.getUTCDate();
     var Month = nd.getUTCMonth()+1;

     var str = new String(currentUTCYear);

     var DM = Day.toString()+Month.toString();
     console.log(DM);

     var dynamicSanURL = "https://somelink"+DM+".someaddress/Some.html";
     this.safeUrl = `this.sanitizer.bypassSecurityTrustResourceUrl(dynamicSanURL);`
  }
}
然后在html中将safeUrl设置为src:

<iframe id="myIframe" [src]="safeUrl" name="targetframe" height="100%" allowTransparency="true" width="100%" scrolling="yes" frameborder="0" >

 </iframe>