2017-04-06 40 views
1

我正在通过html对象标记将pdf加载到视图中。出于某种原因,任何时候在dom中的任何其他地方发生angular2动作(mouseenter,mouseout,click)都会导致对象/ pdf重新加载。我注意到internalInstanceId不断改变对象标签,但我无法控制。当angular2动作发生时,HTML对象标记重新加载

<object type="application/pdf" width="100%" height="100%" [data]="cleanUrl(item.url)" id="pdf_content"></object> 

这是一个显示正在发生什么的plunkr。当一个角度事件发生时(鼠标悬停在标题之外),它会导致对象标签重新加载。

https://plnkr.co/edit/sovRUOn79LTJRDhaellf?p=preview

+1

您必须发布更多相关的代码,以便我们提供帮助。你可以试着在plnkr.co –

+0

上复制这个问题得到一个plunkr与我在谈论的 – jredd

+0

刚刚碰到这个问题,花了我很长时间来注意internalinstanceid增加,每当有一个鼠标悬停 – Joe

回答

1

这真的很有趣,弄明白,事件绑定:mouseentermouseleave触发一个变化检测DoCheck,由于某种原因导致消毒剂来触发或者是其它东西,不知道。

在任何情况下,我固定它通过移动消毒到管道:

@Pipe({ name: 'safeUrl'}) 
export class SafeUrlPipe implements PipeTransform { 
    constructor(private sanitized: DomSanitizer) {} 
    transform(value) { 
    console.log(this.sanitized.bypassSecurityTrustHtml(value)) 
    return this.sanitized.bypassSecurityTrustResourceUrl(value); 
    } 
} 

使用这样的:<object [data]="cleanUrl(item.url) | safeUrl"></object> 看到这个plnkr:https://plnkr.co/edit/10hzOzU31R7CgxJKQaYe?p=preview

而且这个GitHub的问题可能与:https://github.com/angular/angular/issues/7055

相关问题