File

src/domain/domain.directive.ts

Description

The Domain Directive provides access to a specific Domain model

Implements

OnDestroy OnChanges

Example

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

Metadata

providers () ()
selector [arDomain]

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(service: DomainService)

Constructor

Parameters :
Name Type Optional Description
service DomainService

Inputs

arDomain

Sets the ID for the underlying service

Type: string

arModel

Setter for "Banana in a Box Syntax"

Type: Domain

Outputs

arModelChange

Emitter for "Banana in a Box Syntax"

$event type: EventEmitter<Domain>

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

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 { Domain } from '../models/index';
import { odmListenerServiceProvider } from '../sockets/sockets.module';

import { DomainService } from './domain.service';
import { domainServiceProvider } from './domain-service-provider';

/**
 * The Domain Directive provides access to a specific Domain model
 * 
 * @example
 * <div [arDomain]="'DCE:...'" [(arModel)]="my_model">
 */
@Directive({
    selector: '[arDomain]',
    exportAs: 'arDomain',
    providers: [
        odmListenerServiceProvider(),
        domainServiceProvider()
        ]
})
export class DomainDirective implements OnDestroy, OnChanges {

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

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

    /** 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: DomainService) {
        this.modelChange = new EventEmitter<Domain>();
        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) {
        const domainId = 'domainId';
        if (changes.hasOwnProperty(domainId) && this.domainId !== undefined) {
            this.service.uniqueId = this.domainId;
        }
    }

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

results matching ""

    No results matching ""