angular-ui.component.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { Component, Input } from '@angular/core';
  2. import { FormControl } from '@angular/forms';
  3. import { NotificationService, PageMetadataService, SharedModule } from '@vendure/admin-ui/core';
  4. @Component({
  5. selector: 'demo-block',
  6. template: `
  7. <div class="mb-4">
  8. <label>{{ label }}</label>
  9. <div class="mt-1 flex" style="gap: 12px;">
  10. <ng-content />
  11. </div>
  12. </div>
  13. `,
  14. standalone: true,
  15. })
  16. export class DemoBlockComponent {
  17. @Input() label: string;
  18. }
  19. @Component({
  20. selector: 'angular-ui',
  21. templateUrl: './angular-ui.component.html',
  22. standalone: true,
  23. imports: [SharedModule, DemoBlockComponent],
  24. })
  25. export class AngularUiComponent {
  26. pageTitleControl = new FormControl('Angular UI');
  27. invalidFormControl = new FormControl('', () => ({ invalid: true }));
  28. constructor(
  29. private notificationService: NotificationService,
  30. private pageMetadataService: PageMetadataService,
  31. ) {}
  32. canDeactivate() {
  33. return this.pageTitleControl.pristine;
  34. }
  35. updateTitle() {
  36. const title = this.pageTitleControl.value;
  37. if (title) {
  38. this.pageMetadataService.setTitle(title);
  39. this.notificationService.success(`Updated title to "${title}"`);
  40. this.pageTitleControl.markAsPristine();
  41. }
  42. }
  43. }