Quick start with ngx-sonner
masterTo use ngx-sonner, follow these two steps:
- Add the
<ngx-sonner-toaster />component to your application (usually in your root component) to provide the rendering container. - Import and use the
toast()function from anywhere in your app to trigger notifications.
Note: You must include NgxSonnerToaster in your component's imports array if using standalone components.
import { toast, NgxSonnerToaster } from 'ngx-sonner';
@Component({
selector: 'app-root',
imports: [NgxSonnerToaster],
template: `
<ngx-sonner-toaster />
<button (click)="toast('My first toast')">Give me a toast</button>
`
})
export class AppComponent {
protected readonly toast = toast;
}