Jonathan Jonathan - 9 months ago 44
Dart Question

how do I get ngModel attribute as raw string?

The component:

<test [(ngModel)]="someobject.somevar" someattr="someval"></test>


I would like to know the insides of ngModel but as raw string, in the above case, it would be "someobject.somevar".

But when I print the contents of (self.nativeElement as HtmlElement).attributes, it just prints the someattr attribute.

thanks

Answer Source

There is no way to get this information at runtime. The Angular transformer converts such bindings to Dart code (which is subsequently transpiled to JS code), therefore at runtime there won't be such an attribute.

One approach I could imagine, is to create a transformer that processes the template before the Angular transformer does, and secure the information in some form and make it available at runtime. https://pub.dartlang.org/packages/angular_ast can be used for that.