Skip to content
GuidesChecked 18 November 2026

Add a feedback button to Angular

Load the script in index.html, bind the popup after the view exists and release it in ngOnDestroy.

Free for one project and 100 votes. Paid plans start with a 14 day trial, no card.

Load the script

The scripts list in angular.json bundles files from your project and cannot put data attributes on a tag. The VoteFirst tag needs two, so it belongs in the page itself.

Add the tag to src/index.html, not to angular.json.

The page loads it before the Angular bundle starts.

The VoteFirst script reads its project and key from the tag that loaded it, which is why a bundled copy would not work: the bundle has no such tag to read. The hosted file in the head does.

Your project's Share and Embed screen shows the slug and the key. Both are safe to show in page source, because the key only opens the form and takes votes from origins on its list.

src/index.html
<head>
  <meta charset="utf-8" />
  <title>Your app</title>
  <base href="/" />
  <script src="https://app.votefirst.app/embed/votefirst.js" data-project="your-slug" data-key="your-key"></script>
</head>
<body>
  <app-root></app-root>
</body>

The right moment

A button inside the component's template is not in the page during the constructor or ngOnInit. ngAfterViewInit is the first hook where it is.

Bind after the view exists, because the button does not before that.

Use ViewChild to get the real element.

VoteFirst binds to the element it receives at the moment you call it. In ngOnInit the template has not been drawn, so a selector would find nothing and a ViewChild reference would still be empty.

ngAfterViewInit runs once Angular has built the component's view. A ViewChild reference to the button is set by then, and the popup can bind to it directly.

The component

Keep the handle that suggest returns, and call destroy on it when Angular removes the component.

Release the popup in ngOnDestroy.

destroy unbinds the click and closes an open dialog.

The browser check matters only for apps that render on the server, where window does not exist and ngAfterViewInit still runs. In a plain client app the check is always true and costs nothing.

Without ngOnDestroy, each time the route is visited the component is built again and a new listener is added to a new button. Nothing breaks on screen, but dialogs from stale bindings can linger.

src/app/feedback-button.component.ts
import { AfterViewInit, Component, ElementRef, OnDestroy, PLATFORM_ID, ViewChild, inject } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

@Component({
  selector: 'app-feedback-button',
  standalone: true,
  template: '<button #feedbackButton type="button">Feedback</button>',
})
export class FeedbackButtonComponent implements AfterViewInit, OnDestroy {
  @ViewChild('feedbackButton') button?: ElementRef<HTMLButtonElement>;
  private popup?: { destroy: () => void };
  private browser = isPlatformBrowser(inject(PLATFORM_ID));

  ngAfterViewInit() {
    if (this.browser === false || this.button === undefined) return;
    this.popup = (window as any).VoteFirst.suggest({ trigger: this.button.nativeElement });
  }

  ngOnDestroy() {
    this.popup?.destroy();
  }
}

Where it goes

A button in the root template lives as long as the app runs, so it binds once. A button in a routed component binds on each visit.

Put it in the shell component, or in a single route.

Add the component to the imports of its host.

The shell placement suits a small product where every screen should offer the same way to send an idea. A route level button fits a screen with a specific ask, such as an empty report or a failed import.

Style the button with your own classes, and give it a label that says what it does. Send an idea is clearer than an icon alone.

src/app/app.component.ts
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { FeedbackButtonComponent } from './feedback-button.component';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet, FeedbackButtonComponent],
  template: '<app-feedback-button /><router-outlet />',
})
export class AppComponent {}

The board

The popup takes an idea. The public board lists every idea with its status and its votes, and a visitor can vote with no account.

Link a board where every idea is counted.

A suggestion stays hidden until you approve it.

Put the board address in your footer, your help menu or the empty state of a screen. People who open it find the card they meant to write, add a vote and go back to work.

Two cards that say the same thing can be merged, and the votes of both land on the card you keep. A person who voted on each counts once. A subdomain of your own works for the board on the Free and Pro plans.

If it fails

An error that says VoteFirst is undefined means the script tag is missing from index.html or blocked. A button that does nothing usually points at the origin list.

Check for undefined, then the origin list.

The console reports a refused origin as origin_not_allowed.

View the page source and find the tag with its two data attributes. Content blockers sometimes hide scripts from other domains, so test in a clean window.

Add every address you use on Share and Embed, including localhost with the port the Angular dev server uses, which is 4200 unless you changed it.

What an Angular app gains

A life cycle that fits

The popup binds after the view exists and unbinds when the component is destroyed.

Safe on the server

The browser check keeps server rendering from reaching for window.

Votes that add up

Repeat requests land on one card, so the top of the list is what users want most.

Add it in five steps

A tag in the page and one standalone component do the job.

Get the slug and key

Start a Free project and find the slug and key under Share and Embed.

Edit index.html

Place the script tag in the head with its two data attributes.

Write the component

Create the standalone component with ViewChild and the two hooks.

Add it to the shell

Import the component in AppComponent and place its tag in the template.

List your origins

Add your live address and the dev server address to the key.

A check on a real route

Navigate between two routes in the running app and confirm that the button survives, since the shell component should stay mounted. Then resize the window to phone width and check that your button is still easy to reach and tap.

What to know before you set this up

  • Version 2.8.1 of the embed script is what this guide describes, so verify options in the dashboard after a newer release.
  • The tag must be in index.html, since a bundled script has no tag to read its settings from.
  • Only listed origins may open the form, and a dev server on another port needs adding.
  • Free ends at 100 votes, and taking a vote back leaves its slot used.

What Angular developers ask

Does this work with NgModules and not only standalone components?

Yes. Declare the component in a module and use the same two hooks. Only the way it is registered changes.

Why not list the script in angular.json?

That list bundles a file from your project and cannot carry the data attributes the script reads. The tag in index.html can.

Is there an npm package to install?

No. VoteFirst is one hosted file, so the project gains no dependency and the bundle stays the same size.

Does it work with Angular server rendering?

Yes, with the platform check in the component. The server skips the call and the browser makes it after hydration.

What does destroy do?

It unhooks the click from the button and shuts any open dialog.

Does the key have to stay private?

No. Showing it in page source is the intent, since all it allows is the form and votes from listed origins.

Do users need an account to vote?

Not on a new board, where the visitor's browser storage remembers a return visit. A setting makes sign in required if each vote must carry a name.

Can the board run on a subdomain of my site?

Yes, on the Free and Pro plans. Point a name such as feedback.yourapp.com at the board.

Where do new suggestions show up?

They arrive in your dashboard as cards waiting for approval, and the owner gets one email a day at most.

What does it cost to start?

On Free you get one project and 100 votes. Lite at $9/mo and Pro at $39/mo each start with 14 days and no card.

Let the people who use your app steer it

One project and 100 votes cost nothing on Free, and Lite or Pro open with 14 days and no card.