Home > database >  Angular - Get actual HTML element code rather than DOM generated element
Angular - Get actual HTML element code rather than DOM generated element

Time:05-05

I am working on fetching the actual Angular code for any HTML element clicked. For example:

<button (click)="getCode($event)" mat-button>CodeButton</button>

Using this code I can get the generated HTML in a similar way:

<button _ngcontent-buq-c44="" mat-button="">CodeButton</button>

However I would like to fetch the actual source code rather than the generated one. Is it possible?

CodePudding user response:

As far as I understand, you want to get the "uncompiled" html source code of the element? I don't really think that it would be possible. But anyway, for what exactly do you need that? I've never needed that case so far.

If I'd know the use case, there might be a better "workaround" for your situation.

CodePudding user response:

The template you write is not the actual HTML that browser uses to render the page. It is just an intermediate template syntax that angular provides which gets compiled to browser compatible HTML in the build process. So, i do not think there is a way to get the actual template written during development phase.

CodePudding user response:

You can use stackblitz for code snippets.

  • Related