src/component/component.directive.ts
The Component Directive provides access to a specific Component model including the configuration of its properties and access to its ports.
<div [arComponent]="'DCE:...'" [(arModel)]="my_model">
providers |
()
|
selector | [arComponent] |
Properties |
|
Methods |
Inputs |
Outputs |
constructor(service: ComponentService)
|
||||||||
Defined in src/component/component.directive.ts:43
|
||||||||
Constructor
Parameters :
|
arComponent
|
Sets the ID for the underlying service
Type: |
Defined in src/component/component.directive.ts:35
|
arModel
|
Setter for "Banana in a Box Syntax"
Type: |
Defined in src/component/component.directive.ts:38
|
arModelChange
|
Emitter for "Banana in a Box Syntax" $event type: EventEmitter<Component>
|
Defined in src/component/component.directive.ts:40
|
ngOnChanges | ||||||||
ngOnChanges(changes: SimpleChanges)
|
||||||||
Defined in src/component/component.directive.ts:62
|
||||||||
Implementation of the OnChanges interface updates the service's uniqueID
Parameters :
Returns :
void
|
ngOnDestroy |
ngOnDestroy()
|
Defined in src/component/component.directive.ts:71
|
Implementation of the OnDestroy interface unsubscribes from the model observable.
Returns :
void
|
Public service |
service:
|
Type : ComponentService
|
Defined in src/component/component.directive.ts:50
|
The service either imported from up the hierarchy or instantiated by this directive. |
Private subscription |
subscription:
|
Type : Subscription
|
Default value : null
|
Defined in src/component/component.directive.ts:43
|
Internal subscription for the model |
import {
Directive,
OnDestroy,
OnChanges,
SimpleChanges,
Input,
Output,
EventEmitter
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
import { Component } from '../models/index';
// This service
import { ComponentService } from './component.service';
import { componentServiceProvider } from './component-service-provider';
/**
* The Component Directive provides access to a specific Component model including
* the configuration of its properties and access to its ports.
*
* @example
* <div [arComponent]="'DCE:...'" [(arModel)]="my_model">
*/
@Directive({
selector: '[arComponent]',
exportAs: 'arComponent',
providers: [ componentServiceProvider() ]
})
export class ComponentDirective implements OnDestroy, OnChanges {
/**
* Sets the ID for the underlying service
*/
@Input('arComponent') componentId: string;
/** Setter for "Banana in a Box Syntax" */
@Input('arModel') model: Component;
/** Emitter for "Banana in a Box Syntax" */
@Output('arModelChange') modelChange: EventEmitter<Component>;
/** Internal subscription for the model */
private subscription: Subscription = null;
/**
* Constructor
* @param service The service either imported from up the hierarchy or instantiated
* by this directive.
*/
constructor(public service: ComponentService) {
this.modelChange = new EventEmitter<Component>();
this.subscription = this.service.model$.subscribe(it => {
this.model = it;
this.modelChange.emit(this.model);
});
}
/**
* Implementation of the OnChanges interface updates the service's uniqueID
* @param changes The changes made to this component
*/
ngOnChanges(changes: SimpleChanges) {
if (changes.hasOwnProperty('componentId') && this.componentId) {
this.service.uniqueId = this.componentId;
}
}
/**
* Implementation of the OnDestroy interface unsubscribes from the model observable.
*/
ngOnDestroy() {
this.subscription.unsubscribe();
}
}