angular.mdx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ---
  2. slug: /angular
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. # Angular
  7. [Angular][] components for Uppy UI plugins.
  8. ## When should I use it?
  9. When you are using the Angular framework and you would like to use one of the UI
  10. components.
  11. ## Install
  12. <Tabs>
  13. <TabItem value="npm" label="NPM" default>
  14. ```shell
  15. npm install @uppy/angular
  16. ```
  17. </TabItem>
  18. <TabItem value="yarn" label="Yarn">
  19. ```shell
  20. yarn add @uppy/angular
  21. ```
  22. </TabItem>
  23. </Tabs>
  24. :::note
  25. You also need to install the UI plugin you want to use. For instance,
  26. `@uppy/dashboard`.
  27. :::
  28. ## Use
  29. Instead of adding a UI plugin to an Uppy instance with `.use()`, the Uppy
  30. instance can be passed into components as a `props` prop.
  31. The following plugins are available as Angular component wrappers:
  32. - `<uppy-dashboard />` renders [`@uppy/dashboard`](/docs/dashboard)
  33. - `<uppy-drag-drop />` renders [`@uppy/drag-drop`](/docs/drag-drop)
  34. - `<uppy-progress-bar />` renders [`@uppy/progress-bar`](/docs/progress-bar)
  35. - `<uppy-status-bar />` renders [`@uppy/status-bar`](/docs/status-bar)
  36. Each component takes a `props` prop that will be passed to the UI Plugin.
  37. ```typescript title="app.module.ts" showLineNumbers
  38. import { NgModule } from '@angular/core';
  39. import { UppyAngularDashboardModule } from '@uppy/angular';
  40. import { BrowserModule } from '@angular/platform-browser';
  41. import { AppComponent } from './app.component';
  42. @NgModule({
  43. declarations: [AppComponent],
  44. imports: [BrowserModule, UppyAngularDashboardModule],
  45. providers: [],
  46. bootstrap: [AppComponent],
  47. })
  48. class {}
  49. ```
  50. ```html title="app.component.html" showLineNumbers
  51. <uppy-dashboard [uppy]="uppy"> </uppy-dashboard>
  52. ```
  53. You should initialize Uppy as a property of your component.
  54. ```typescript title="app.component.ts" showLineNumbers
  55. import { Component } from '@angular/core';
  56. import { Uppy } from '@uppy/core';
  57. @Component({
  58. selector: 'app-root',
  59. })
  60. export class AppComponent {
  61. uppy: Uppy = new Uppy({ debug: true, autoProceed: true });
  62. }
  63. ```
  64. ### CSS
  65. All components have their own styling and should be added to your component
  66. decorator. You can find the CSS import statements in the docs of the UI plugin
  67. you want to use. For instance, for `@uppy/dashboard`:
  68. ```typescript
  69. import { Component, ViewEncapsulation } from '@angular/core';
  70. //...
  71. @Component({
  72. // ...
  73. encapsulation: ViewEncapsulation.None,
  74. styleUrls: [
  75. '../node_modules/@uppy/core/dist/style.css',
  76. '../node_modules/@uppy/dashboard/dist/style.css',
  77. ],
  78. })
  79. ```
  80. [angular]: https://angular.io