Angular component that interacts with the Storybook using Actions

I'm having trouble connecting the eventemitter of an Angular button to Storybook actions. The action doesn't seem to be triggering even though I can see in the console that the button is being clicked. However, it's not showing up in the actions tab in Storybook.

Is there a way to get the click event to appear in the actions tab in Storybook?

button.component.html

<button class="button" (click)="handleClick()">Save</button>

button.component.ts

import { Component, EventEmitter, Output } from '@angular/core';

@Component({
  selector: 'ad-button',
  templateUrl: './button.component.html',
  styleUrls: ['./button.component.scss'],
})
export class ButtonComponent {
  @Output()
  buttonclick = new EventEmitter();

  constructor() {}

  handleClick() {
    this.buttonclick.emit();
    console.log('clicked');
  }
}

button.stories.ts

import { Story, Meta } from '@storybook/angular';
import { ButtonComponent } from './button.component';

export default {
  title: 'Components/Button',
  component: ButtonComponent,
  argTypes: { buttonClick: { action: 'buttonClick' } },
} as Meta;

const Template: Story<ButtonComponent> = (args: ButtonComponent) => ({
  props: args,
});

export const Primary = Template.bind({});
Primary.args = {};

Answer №1

After much experimentation, I finally got it functioning properly by including

changeDetection: ChangeDetectionStrategy.OnPush
in the Component decorator.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for accessing a specific ListItem within the Menu Component using MUI for React

Within my code, I am working with a List that contains multiple ListItems pulled from an array called myCollection. Each ListItem has a MenuIcon element which triggers a menu to appear, providing the option to delete the specific item. Here is a simplified ...

A fresh perspective on incorporating setInterval with external scripts in Angular 7

Incorporating the header and footer of my application from external JavaScript files is essential. The next step involves converting it to HTML format and appending it to the head of an HTML file. private executeScript() { const dynamicScripts = [this.app ...

The act of exporting an enum from a user-defined TypeScript path leads to the error message "Module not

I have set up a custom path as explained in this particular discussion. "baseUrl": ".", "paths": { "@library/*": [ "./src/myFolder/*" ], } Within this module, I am exporting an Enum. export enum EN ...

Displaying a specific item depending on the pathname within a NextJs Server Component

I am working on a layout that consists of two Detail Pages: User and Company. Based on the page they are in, I need to highlight either the user or company tab. The URLs are as follows: /user/details /company/details I want to ensure that the correct tab ...

The callback type in TypeScript is used to define the types

I have encountered this scenario: function createCar(name: string, callback: () => void) function buildEngine(name: string): Engine function createCarWithEngine(carName: string, engineName: string, callback: (param: Engine) => void) { let created ...

Encountering the error "Type error: Property X is missing" while working with Angular 2

Receiving the following error: Property 'conf' is absent in the type '{ text: string; label: string; }'. when trying to access it from this object: { //... digitalSkills: { skills: [ { name: '...', ...

Why doesn't angular generate ng-reflect-_opened="false" in its production build?

We are currently utilizing the following technologies (which cannot be changed in the near future): Angular 2 RC5 Angular CLI 1.0.0-beta.10 Material Design Side Nav Control Node 6.9.1 npm 3.10.8 Windows 10 When we compile the code (using ng serve with d ...

What is the best way to create a nullable object field in typescript?

Below is a function that is currently working fine: export const optionsFunc: Function = (token: string) => { const options = { headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, } ...

Error encountered in Typescript: The method date.getDate is not recognized as a

My goal is to retrieve the date from the first input control and the number of days from the other input controls, add them together, and assign the result to the third date control using TypeScript. However, I am encountering an error with the following c ...

Leverage predefined JavaScript functions within an Angular template

I have been attempting to execute an eval function within my angular template in the following manner: <div *ngFor="..."> <div *ngIf="eval('...')"></div> </div> You understand what I'm trying to ...

Problem with Angular Service Injection: @Injectable Doesn't Function Properly, While Providers Do

After searching through SO, I couldn't find any solutions to my unique issue. Let me provide some context by sharing snippets of my code: My Service: import { Injectable } from '@angular/core'; import { MyModule } from './my.module&a ...

Tips for saving metadata about properties within a class

I am looking to add metadata to properties within classes, specifically using abbreviations for property names. By using annotations like @shortName(abbreviated), you can label each property as follows: function shortName(shortName: string){ return fu ...

Is Angular 11 Compatible with Internet Explorer 5?

Is there a way to make Angular 11 compatible with Internet Explorer 5? I am developing an angular solution for a client whose default browser is Internet Explorer running on version 5 (by default). Initially, I am not supposed to change any browser configu ...

I am unable to utilize autocomplete with types that are automatically generated by Prisma

Currently, I am working on a project utilizing Next and Prisma. Within my schema.prisma file, there are various models defined, such as the one shown below: model Barbershop { id String @id @default(uuid()) name String address String ...

Troubleshooting the TS2559 error when using radium in React typescript: CSSProperties type mismatch

Looking to integrate Typescript into React and incorporate some styling using Radium. I understand that JSX style does not support media queries, but I'm unsure how to resolve this issue. Can anyone provide guidance? Thank you! Encountering errors w ...

Angular 2 project experiencing issues with implementing Bootstrap styles

After adding Bootstrap CSS to angular-cli.json - styles, I noticed that the styles were not being applied to my project. I also added it in package.json and did an npm install. Can anyone suggest a solution? Here is a snippet from angular-cli.json: ...

script code to limit selection of dates within a predefined range

I'm seeking assistance to limit my customers from selecting a date beyond 10 days in advance. Although I previously had a code that functioned properly when there were more than 10 days left in the current month, it is now ineffective. This is becaus ...

Utilizing CSS classes to style custom day templates in ng-bootstraps datepicker

Currently, I am utilizing ng-bootstraps datepicker to showcase user data on a daily basis. I have implemented a custom day template to apply specific CSS classes. <ng-template #customDay let-date> <div class="custom-day" [ngCla ...

Issue encountered in Angular 2 while attempting to import TypeScript classes using a single file

Upon loading my Angular 2 application, I encountered the following error: EXCEPTION: Error: Uncaught (in promise): Unexpected piped value 'undefined' on the View of component 'DashboardComponent' An interesting observation is that by ...

Ignore one specific file when importing all files in Angular 7

In my Angular 7 project, I am utilizing C3 and importing all the necessary files at the beginning of my .ts component file using a wildcard. import * as c3 from 'c3'; While this method works well overall, I encountered an issue where my CSS ove ...