I've started learning Angular recently one problem very simple (I think) which I can't find a solution is the following one:
I want to create a Component with a custom attribute without a value. Like this one:
<h1 attribute-without-value > Text <h1>
I tried in a different way but still, I don't have what I want.
I'm able to create an attribute with a value using this syntax: [attr.attr-with-value]="value" but not without.
Here some of my experiment (ref: https://stackblitz.com/edit/angular-sn94cl?embed=1&file=src/app/app.component.ts):
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<h1 {{nameAttr}} > doesn\'t work <h1>
<h1 [attr.nameAttr] > also this doesn\'t work <h1>
`,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
nameAttr = 'attribute-without-value';
}
How can I do?
<h1 attribute-without-value >should work and add the attribute, as shown in this stackblitz. Do you need the attribute name to be dynamic?