URL sanitization is causing refresh of the embedded YouTube video

后端 未结 5 1320
春和景丽
春和景丽 2021-02-02 06:15

I have a problem with my AngularJS 2 app (I am using RC5 version of AngularJS 2). It seems that a sanitized URL is triggering change detection which then updates the div

5条回答
  •  無奈伤痛
    2021-02-02 06:38

    I would try to use it with pure pipe

    Angular executes a pure pipe only when it detects a pure change to the input value. A pure change is either a change to a primitive input value (String, Number, Boolean, Symbol) or a changed object reference (Date, Array, Function, Object).

    Pipe might look like (RC.6 - DomSanitizer becomes instead of DomSanitizationService):

    @Pipe({ name: 'safe' })
    export class SafePipe implements PipeTransform {
      constructor(private sanitizer: DomSanitizer) {}
      transform(url) {
        return this.sanitizer.bypassSecurityTrustResourceUrl(url);
      }
    }
    

    And use it as the following:

     
    

    Plunker Example (try to push button)

提交回复
热议问题