diff --git a/components/togglebutton/togglebutton.ts b/components/togglebutton/togglebutton.ts
index 6ccd3a8bf80..ac9c1fad2ce 100644
--- a/components/togglebutton/togglebutton.ts
+++ b/components/togglebutton/togglebutton.ts
@@ -1,14 +1,22 @@
-import {Component, ElementRef, OnInit, OnDestroy, OnChanges, Input, Output, SimpleChange, EventEmitter} from 'angular2/core';
+import {Component,Input,Output,EventEmitter} from 'angular2/core';
@Component({
selector: 'p-toggleButton',
- template:''
+ template: `
+
+
+
+ {{checked ? onLabel : offLabel}}
+
+ `
})
-export class ToggleButton implements OnInit, OnDestroy, OnChanges {
+export class ToggleButton {
- @Input() onLabel: string;
+ @Input() onLabel: string = 'Yes';
- @Input() offLabel: string;
+ @Input() offLabel: string = 'No';
@Input() onIcon: string;
@@ -25,51 +33,21 @@ export class ToggleButton implements OnInit, OnDestroy, OnChanges {
@Output() onChange: EventEmitter = new EventEmitter();
@Output() checkedChange: EventEmitter = new EventEmitter();
+
+ private hover: boolean;
- initialized: boolean;
-
- stopNgOnChangesPropagation: boolean;
-
- constructor(private el: ElementRef) {
- this.initialized = false;
- }
-
- ngOnInit() {
- jQuery(this.el.nativeElement.children[0]).puitogglebutton({
- onLabel: this.onLabel,
- offLabel: this.offLabel,
- onIcon: this.onIcon,
- offIcon: this.offIcon,
- checked: this.checked,
- disabled: this.disabled,
- style: this.style,
- styleClass: this.styleClass,
- change: (event: Event, ui: PrimeUI.ToggleButtonEventParams) => {
- this.stopNgOnChangesPropagation = true;
- this.checkedChange.next(ui.checked);
- if (this.onChange) {
- this.onChange.next({originalEvent: event, checked: ui.checked});
- }
- }
- });
- this.initialized = true;
+ getIconClass() {
+ let baseClass = 'ui-button-icon-left fa fa-fw';
+ return baseClass + ' ' + (this.checked ? this.onIcon : this.offIcon);
}
-
- ngOnChanges(changes: { [key: string]: SimpleChange }) {
- if (this.initialized) {
- for (var key in changes) {
- if (key == 'checked' && this.stopNgOnChangesPropagation) {
- this.stopNgOnChangesPropagation = false;
- continue;
- }
-
- jQuery(this.el.nativeElement.children[0].children[0]).puitogglebutton('option', key, changes[key].currentValue);
- }
+
+ toggle(event) {
+ if(!this.disabled) {
+ this.checkedChange.next(!this.checked);
+ this.onChange.next({
+ originalEvent: event,
+ checked: !this.checked
+ })
}
}
-
- ngOnDestroy() {
- jQuery(this.el.nativeElement.children[0].children[0]).puitogglebutton('destroy');
- this.initialized = false;
- }
}
\ No newline at end of file