1

I'm trying to create a button that upon clicking would open a certain modal that is decided by the controller in a variable instead of just having multiple buttons that have the same attributes but with different data-targets

So this is one of the buttons that I was using earlier

      <button mat-menu-item class="menu-item" *ngIf="isReady"
              data-toggle="modal" data-target="#ready-modal">
        <span>View Ready</span>
      </button>

and here's what I came up with

      <button mat-menu-item class="menu-item" data-toggle="modal"
        data-target="{{action.dataModalTarget}}" (click)="this[action.clickFunction](event)">
          <span>{{action.translationKey | translate}}</span>
      </button>

however, this throws the following exception,

Can't bind to 'target' since it isn't a known property of 'button'. ("      <button mat-menu-item class="menu-item" data-toggle="modal"

is this even doable or not ?

1 Answer 1

4

You can do it via attribute binding, just like you bind properties and events, the syntax for attribute binding is:

[attr.<attribute_name>]="value"
[attr.data-target]="action.dataModalTarget"

Reference: Angular doumentation

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, could you tell me what attr refer to, or guide me to somewhere I can read a bit more about this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.