ngx-input-switch
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

ngx-input-switch

Demo

Installation

To install this library, run:

npm install ngx-input-switch --save

and then from your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { NgxInputSwitchModule } from 'ngx-input-switch';
 
import { AppComponent } from './app.component';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    ReactiveFormsModule,
    NgxInputSwitchModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Component

Once the library is imported, you can use the ngx-input-switch component.

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Observable } from 'rxjs/Observable';
 
@Component({
  selector: 'app-root',
  template: `
<h1>ngx-input-switch</h1>
 
<form [formGroup]="form" (ngSubmit)="submit()">
  <ngx-input-switch formControlName="switch"></ngx-input-switch>
  <button>Submit</button>
</form>
  `
})
export class AppComponent implements OnInit {
  form: FormGroup;
  value: Observable<number>;
 
  constructor(private formBuilder: FormBuilder) { }
 
  ngOnInit() {
    this.form = this.formBuilder.group({
      switch: [true]
    });
 
    this.value = this.form.controls.switch.valueChanges;
  }
 
  submit() {
    console.log(this.form.value);
  }
}

License

MIT © Cory Rylan

Readme

Keywords

none

Package Sidebar

Install

npm i ngx-input-switch

Weekly Downloads

8

Version

0.0.1

License

MIT

Unpacked Size

45.2 kB

Total Files

15

Last publish

Collaborators

  • splintercode