:

后端 未结 9 1270
情深已故
情深已故 2020-11-27 12:54

Since upgrading to the latest Angular 2 release candidate, my img tags:



        
9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 13:16

    I'm using rc.4 and this method works for ES2015(ES6):

    import {DomSanitizationService} from '@angular/platform-browser';
    
    @Component({
      templateUrl: 'build/pages/veeu/veeu.html'
    })
    export class VeeUPage {
      static get parameters() {
        return [NavController, App, MenuController, DomSanitizationService];
      }
    
      constructor(nav, app, menu, sanitizer) {
    
        this.app = app;
        this.nav = nav;
        this.menu = menu;
        this.sanitizer = sanitizer;    
      }
    
      photoURL() {
        return this.sanitizer.bypassSecurityTrustUrl(this.mediaItems[1].url);
      }
    }
    

    In the HTML:

    
    

    Using a function will ensure that the value doesn't change after you sanitize it. Also be aware that the sanitization function you use depends on the context.

    For images, bypassSecurityTrustUrl will work but for other uses you need to refer to the documentation:

    https://angular.io/docs/ts/latest/api/platform-browser/index/DomSanitizer-class.html

提交回复
热议问题