0

I have an array to store the alerts to display.

appLevelAlert

     const alert = {
     message: 'Your account is not activated.'
      + ' Select the link in your email inbox to activate your account',
      actionName: 'Resend Email',
      action: 'resendEmail()'
    };

    this.appLevelAlert = this.appLevelAlert || [];
    this.appLevelAlert.push(alert);

I would like to assign the resendEmail() in appLevelAlert.action to the (Click) of a button.

<clr-alert [clrAlertType]="'info'" [clrAlertAppLevel]="true" *ngFor='let alert of clarityAlertService.appLevelAlert'>
<clr-alert-item>
    <span class="alert-text">
        {{alert.message}}
    </span>
    <div class="alert-actions">
        <button class="btn alert-action" (click)="[alert.action]">{{alert.actionName}}</button>
    </div>  
</clr-alert-item>

I'm not sure if this is possible, can anyone help me on this?

1
  • 1
    action: 'resendEmail()' in your example is a string, change it to an inline-function, then call it (click)="alert.action()" Commented Jan 3, 2019 at 9:03

1 Answer 1

3

This is a simplified working example:

import { Component } from '@angular/core';

@Component({
   selector: 'my-app',
   template: `<p>{{alert.message}}</p>
   <button type="button" (click)="alert.action()">{{alert.actionName}}</button>`
})
export class AppComponent  {

    readonly alert = {
        message: 'Your account is not activated.',
        actionName: 'Resend Email',
        action: () => this.resendEmail()
    };

    resendEmail() {
        console.log('send email');
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.