Project

General

Profile

1
/**
2
 * Created by stefanos on 19/5/2017.
3
 */
4
import { EventEmitter, Input, OnInit, Output, ViewChild, ViewRef } 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
export abstract class MyWrapper implements OnInit{
11

    
12
  @Input() public component: ViewRef;
13

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

    
16
  @Input() viewRef: ViewRef;
17

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

    
20
  @ViewChild(MyFormDirective) private formComponents: MyFormDirective;
21

    
22
  public first = true;
23

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

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

    
36

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

    
41
}
(4-4/4)