File

src/sample/sample.component.ts

Description

This is a sample component to demonstrate how components should be written, and can be used as a template for new components

Implements

OnInit AfterViewInit OnDestroy

Metadata

selector ibm-sample

Index

Methods
Inputs
Outputs

Constructor

constructor(_elementRef: ElementRef)

instantiate services as private variables

Parameters :
Name Type Optional Description
_elementRef ElementRef

Inputs

foo

foo is an input that takes a SampleInterface

Type: SampleInterface

Outputs

bar

bar is an event that emits a SampleInterface

$event type: EventEmitter<SampleInterface>

Methods

Public doBar
doBar(value: )

this is an instance method that can be used in templates

Parameters :
Name Type Optional Description
value
Returns : void
ngAfterViewInit
ngAfterViewInit()

run setup logic that depends on the DOM here

Returns : void
ngOnDestroy
ngOnDestroy()

clean up any event handlers or other objects that won't normally be destroyed

Returns : void
ngOnInit
ngOnInit()

run setup logic that doesnt depend on the DOM and only needs to be run once here

Returns : void
Protected setFoo
setFoo(value: SampleInterface)

this is an instance method that can be inherited and used by subclasses

Parameters :
Name Type Optional Description
value SampleInterface
Returns : void
import {
	Component,
	Input,
	Output,
	EventEmitter,
	ElementRef,
	OnInit,
	AfterViewInit,
	OnDestroy
} from "@angular/core";

import { SampleBase } from "./sample-base.class";
import { SampleInterface } from "./sample.interface";

/**
 * This is a sample component to demonstrate how components should be written, and can be used as a template for new components
 */
@Component({
	selector: "ibm-sample",
	template: `
		<p>Hello, Neutrino!</p>
		<span>{{ foo.required }}</span>
	`
})
export class Sample implements OnInit, AfterViewInit, OnDestroy {
	/** foo is an input that takes a SampleInterface */
	@Input() foo: SampleInterface;
	/** bar is an event that emits a SampleInterface */
	@Output() bar: EventEmitter<SampleInterface> = new EventEmitter<SampleInterface>();

	/**
	 * instantiate services as private variables
	 *
	 * @param {ElementRef} _elementRef
	 */
	constructor(private _elementRef: ElementRef) {}

	/** run setup logic that doesnt depend on the DOM and only needs to be run once here */
	ngOnInit() {
		//
	}

	/** run setup logic that depends on the DOM here */
	ngAfterViewInit() {
		//
	}

	/** clean up any event handlers or other objects that won't normally be destroyed */
	ngOnDestroy() {
		//
	}

	/** this is an instance method that can be used in templates */
	public doBar(value) {
		this.bar.emit(value);
	}

	/** this is an instance method that can be inherited and used by subclasses */
	protected setFoo(value: SampleInterface) {
		this.foo = value;
	}
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""