---
agentTools:
  projectIndex: https://laravel-angular.readme.io/llms.txt
---

# Toasts

[block:image]
{
  "images": [
    {
      "image": [
        "https://files.readme.io/RwcOkVjFSLeN2uvHdRcL_1XhwWRQ.png",
        "1XhwWRQ.png",
        "504",
        "180",
        "#343434",
        ""
      ]
    }
  ]
}
[/block]

[Toasts](https://material.angularjs.org/latest/demo/toast) are a component available in Angular Material.

Since most implementations require a success and an error toast, this repository provides you with pre-configured `ToastService` that you can easily adjust to fit your needs.

This service allows you to open a success toast and an error toast.
The error toast is also automatically displayed when the API encounters a validation error (using restangular's [error interceptor](https://laravel-angular.readme.io/docs/restangular)).

While this service has a default delay, position and action text, you can easily change them in `angular/services/toast.service.js`. You can also add custom methods.

[block:code]
{
  "codes": [
    {
      "code": "export class PostsController(){\n  constructor(ToastService){\n      'ngInject';\n    \tthis.ToastService = ToastService;\n  }\n  \n  success(){\n\t\tthis.ToastService.show('Post added successfully!');\n\t}\n    \n  error(){\n\t\tthis.ToastService.error('Connection interrupted!');\n\t}\n}",
      "language": "javascript",
      "name": "Toasts Sample"
    }
  ]
}
[/block]