File

src/port/port.directive.ts

Description

The Port directive provides access to the variety of port types in REDHAWK. Port-specific features can be accessed through the 'service'.

Implements

OnDestroy OnChanges

Example

<div [arPort]="'dataShort_out'" [(arModel)]="my_model">

Metadata

providers ()
selector [arPort]

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(service: PortService)

Constructor

Parameters :
Name Type Optional Description
service PortService

Inputs

arModel

Setter for "Banana in a Box Syntax"

Type: Port

arPort

Sets the ID for the underlying service

Type: string

Outputs

arModelChange

Emitter for "Banana in a Box Syntax"

$event type: EventEmitter<Port>

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: PortService
Type : PortService

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';

// This model, rest service, and provider
import { Port }                from '../models/index';
import { PortService }         from './port.service';
import { portServiceProvider } from './port-service-provider';

/**
 * The Port directive provides access to the variety of port types in REDHAWK.
 * Port-specific features can be accessed through the 'service'.
 * 
 * @example
 * <div [arPort]="'dataShort_out'" [(arModel)]="my_model">
 */
@Directive({
    selector: '[arPort]',
    exportAs: 'arPort',
    providers: [ portServiceProvider() ]
})
export class PortDirective implements OnDestroy, OnChanges {

    /**
     * Sets the ID for the underlying service
     */
    @Input('arPort') portId: string;

    /** Setter for "Banana in a Box Syntax"  */
    @Input('arModel') model: Port;
    /** Emitter for "Banana in a Box Syntax"  */
    @Output('arModelChange') modelChange: EventEmitter<Port>;

    /** 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: PortService) {
        this.modelChange = new EventEmitter<Port>();
        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('portId') && this.portId) {
            this.service.uniqueId = this.portId;
        }
    }

    /**
     * Implementation of the OnDestroy interface unsubscribes from the model observable.
     */
    ngOnDestroy() {
        this.subscription.unsubscribe();
    }
}

results matching ""

    No results matching ""