File

src/component/component.directive.ts

Description

The Component Directive provides access to a specific Component model including the configuration of its properties and access to its ports.

Implements

OnDestroy OnChanges

Example

<div [arComponent]="'DCE:...'" [(arModel)]="my_model">

Metadata

providers ()
selector [arComponent]

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(service: ComponentService)

Constructor

Parameters :
Name Type Optional Description
service ComponentService

Inputs

arComponent

Sets the ID for the underlying service

Type: string

arModel

Setter for "Banana in a Box Syntax"

Type: Component

Outputs

arModelChange

Emitter for "Banana in a Box Syntax"

$event type: EventEmitter<Component>

Methods

ngOnChanges
ngOnChanges(changes: SimpleChanges)

Implementation of the OnChanges interface updates the service's uniqueID

Parameters :
Name Type Optional Description
changes SimpleChanges

The changes made to this component

Returns : void
ngOnDestroy
ngOnDestroy()

Implementation of the OnDestroy interface unsubscribes from the model observable.

Returns : void

Properties

Public service
service: ComponentService
Type : ComponentService

The service either imported from up the hierarchy or instantiated by this directive.

Private subscription
subscription: Subscription
Type : Subscription
Default value : null

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();
    }
}

results matching ""

    No results matching ""