0.1.0 • Published 8 years ago

ng2-toggle v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Toggle for Angular 2

Demo

Toggle between the toggle component and the toggle directive.

import { Component } from '@angular/core';
import { ToggleComponent, ToggleDirective } from 'ng2-toggle';

@Component({
  directives: [ ToggleComponent, ToggleDirective ],
  template: `
    <toggle #toggler>
      <p>Toggled!</p>
    </toggle>
    <p *toggle="toggler">Click the button below to toggle.</p>
    <button type="button" (click)="toggler.toggle()">Toggle</button>
  `
})
export class DemoComponent {}

Toggle from the component and subscribe to the toggle change event.

import { Component, OnInit, ViewChild } from '@angular/core';
import { ToggleComponent, ToggleDirective } from 'ng2-toggle';

@Component({
  directives: [ ToggleComponent, ToggleDirective ],
  template: `
    <toggle #toggler>
      <p>Toggled!</p>
    </toggle>
    <p *toggle="toggler">Click the button below to toggle.</p>
    <button type="button" (click)="toggle()">Toggle</button>
  `
})
export class DemoComponent implements OnInit {
  @ViewChild('toggler')
  toggler: ToggleComponent;
  ngOnInit() {
    this.toggler.change.subscribe(on => console.log(on));
  }
  toggle() {
    this.toggler.toggle();
  }
}