angular.mdx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. - Import `UppyAngularDashboardModule` used as `<uppy-dashboard>` renders
  33. [`@uppy/dashboard`](/docs/dashboard)
  34. - Import `UppyAngularDashboardModalModule` used as `<uppy-dashboard-modal>`
  35. renders [`@uppy/dashboard`](/docs/dashboard) as a modal
  36. - Import `UppyAngularProgressBarModule` used as `<uppy-progress-bar>` renders
  37. [`@uppy/progress-bar`](/docs/progress-bar)
  38. - Import `UppyAngularStatusBarModule` used as `<uppy-status-bar>` renders
  39. [`@uppy/status-bar`](/docs/status-bar)
  40. - Import `UppyAngularDragDropModule` used as `<uppy-drag-drop>` renders
  41. [`@uppy/drag-drop`](/docs/drag-drop)
  42. Each component takes a `props` prop that will be passed to the UI Plugin.
  43. ```typescript title="app.module.ts" showLineNumbers
  44. import { NgModule } from '@angular/core';
  45. import { UppyAngularDashboardModule } from '@uppy/angular';
  46. import { BrowserModule } from '@angular/platform-browser';
  47. import { AppComponent } from './app.component';
  48. @NgModule({
  49. declarations: [AppComponent],
  50. imports: [BrowserModule, UppyAngularDashboardModule],
  51. providers: [],
  52. bootstrap: [AppComponent],
  53. })
  54. class {}
  55. ```
  56. ```html title="app.component.html" showLineNumbers
  57. <uppy-dashboard [uppy]="uppy"> </uppy-dashboard>
  58. ```
  59. You should initialize Uppy as a property of your component.
  60. ```typescript title="app.component.ts" showLineNumbers
  61. import { Component } from '@angular/core';
  62. import { Uppy } from '@uppy/core';
  63. @Component({
  64. selector: 'app-root',
  65. })
  66. export class AppComponent {
  67. uppy: Uppy = new Uppy({ debug: true, autoProceed: true });
  68. }
  69. ```
  70. ### CSS
  71. All components have their own styling and should be added to your component
  72. decorator. You can find the CSS import statements in the docs of the UI plugin
  73. you want to use. For instance, for `@uppy/dashboard`:
  74. ```typescript
  75. import { Component, ViewEncapsulation } from '@angular/core';
  76. //...
  77. @Component({
  78. // ...
  79. encapsulation: ViewEncapsulation.None,
  80. styleUrls: [
  81. '../node_modules/@uppy/core/dist/style.css',
  82. '../node_modules/@uppy/dashboard/dist/style.css',
  83. ],
  84. })
  85. ```
  86. [angular]: https://angular.io