puddlejumper26 / blogs

Personal Tech Blogs
4 stars 1 forks source link

Create a valid hyperlink inside a dialog (Angular) #30

Open puddlejumper26 opened 4 years ago

puddlejumper26 commented 4 years ago

Normally because of the dialog, for example, when you are on a page, and click a button, which would pop up a dialog in the front, and on this dialog, we need to create a hyperlink, when it is clicked, it would leads to somewhere inside this dialog.

Then we could not use normal id binding method, which will lead to totally different places.

html for the dialog

<a (click)="jumpTo('detailedContent')" >Click Button</a>

<div id="detailedContent">Content</div>

component file inside angular

publick jumpTo(id:string){
   const elem = document.getElementById(id);
   if (elem) { 
      elem.screenIntoView();
   }
}