Project

General

Profile

1
/**
2
 * Created by stefanos on 19/5/2017.
3
 */
4
import { EventEmitter, Input, OnInit, Output, ViewChild, ViewRef, Directive } from '@angular/core';
5
import { Description } from '../../../domain/oa-description';
6
import { MyFormDirective } from './my-form.directive';
7
import { throwError } from 'rxjs';
8

    
9

    
10
@Directive()
11
export abstract class MyWrapper implements OnInit{
12

    
13
  @Input() public component: ViewRef;
14

    
15
  @Input() description: Description = null;
16

    
17
  @Input() viewRef: ViewRef;
18

    
19
  @Output() deleteNotifier: EventEmitter<ViewRef> = new EventEmitter();
20

    
21
  @ViewChild(MyFormDirective, { static: true }) private formComponents: MyFormDirective;
22

    
23
  public first = true;
24

    
25
  ngOnInit() {
26
    if (!this.formComponents) {
27
      console.log(this.formComponents);
28
      throwError('Maybe you forgot [my-form] directive in the template');
29
    }
30
    this.formComponents.viewContainerRef.insert(this.component);
31
  }
32

    
33
  public remove() {
34
    this.deleteNotifier.emit(this.viewRef);
35
  }
36

    
37

    
38
  public get canDelete() {
39
    return !((this.description.mandatory === true) && (this.first === true));
40
  }
41

    
42
}
(4-4/4)