1

I try to have a PDF viewer inside of a component.

For dynamically changing the PDF document within a sanitizer I need to set it by an attribute with [].

That is OK with img.

 <img src="assets/pic.jpg"/>
 <img [src]="'assets/pic.jpg'"/>

But NOT with object.

<object data="assets/test.pdf" type="application/pdf" width="300" height="200"></object>
<object [data]="'assets/test.pdf'" type="application/pdf" width="300" height="200"></object>

Why is that?

How can I set data dynamically as a result of a function.

1
  • You can try adding a *ngIf on the object element to show it when the URL is resolved and available. Commented Jun 25, 2019 at 22:12

1 Answer 1

1

Working Demo Here

You will need to sanitize and specify a SafeResource URL. See here

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

export class AppComponent  {
  name = 'Angular';
   constructor(protected _sanitizer: DomSanitizer) {}

    get resolveURL() : SafeResourceUrl {
    // some logic to reolve and return the URL
    return this._sanitizer.bypassSecurityTrustResourceUrl('https://www.orimi.com/pdf-test.pdf')
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.