Question: I am loading an image in a new window when user click a button in Angular.
The popup which I opened contains HTML.

Angular HTML:

```
<button class="btn btn-primary" type="button" (click)="openDocument(doc)"> View </button>

```

TS:

```
openDocument(doc) {
    doc.uploadedDocUrl = "https://beta.lottoweaver.com/WeaverDoc/commonContent/www.nationallottery.co.za/playerDocument/408441_ID_PROOF_null_1616082462069.pdf"

    let str = `<embed src=${doc.uploadedDocUrl} width='100%' height="100%">`;

    this.OpenWindow = window.open('', '', 'width=900, height=600, left=200, top=100');
    this.OpenWindow.document.write(`<body onload="checkIfPdf(${doc.uploadedDocUrl})">${str}</body>
    <script>
    function checkIfPdf(doc) {
      if(doc.endsWith(".pdf")) {
        console.log("is pdf")
      } else {
        console.log("is not pdf")
     }
    }
    </script>
    `);
    this.OpenWindow.document.close();
  }

```

I want keep width and height attributes as `100%` if the doc file ends with ".pdf"
else I want to keep width and height attributes as `auto`.

How to write this condition?

Working stackblitz= <https://stackblitz.com/edit/angular-ivy-ns536z>

Answer: 
I don't know angular but. your code is like

```
 <script>
   function checkIfPdf(doc) {
   if(doc.endsWith(".pdf")) {
   console.log("is pdf")
   } else {
   console.log("is not pdf")
   }
   }
   </script>
  `);
   this.OpenWindow.document.close();
you may check with 

   <script>
  function checkIfPdf(doc) {
   if(doc.endsWith(".pdf")) {
   console.log("is pdf")
   } else {
   console.log("is not pdf")
   }
   }
  `);
   this.OpenWindow.document.close();
  </script>

```
You have to use nested if

It may go like this

```
if (condition a) 
{
    do action 1
} else 
{
   if (condition b) 
   {
     do action 2
   } 
   else 
   {
     ... etc.
   }
}

```