-
-
Notifications
You must be signed in to change notification settings - Fork 902
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ng-option): support for disabled attribute (#280)
closes #236
- Loading branch information
1 parent
8a23b71
commit a5e2d16
Showing
5 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
import { Component, Input, ElementRef } from '@angular/core'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
Input, | ||
OnChanges, | ||
SimpleChanges | ||
} from '@angular/core'; | ||
import { Subject } from 'rxjs/Subject'; | ||
|
||
@Component({ | ||
selector: 'ng-option', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
template: `<ng-content></ng-content>` | ||
}) | ||
export class NgOptionComponent { | ||
export class NgOptionComponent implements OnChanges { | ||
|
||
@Input() value: any; | ||
@Input() | ||
get disabled() { return this._disabled; } | ||
set disabled(value: any) { this._disabled = this._isDisabled(value) } | ||
|
||
readonly stateChange$ = new Subject<{ value: any, disabled: boolean }>(); | ||
private _disabled = false; | ||
|
||
constructor(public elementRef: ElementRef) { } | ||
|
||
ngOnChanges(changes: SimpleChanges) { | ||
if (changes.disabled) { | ||
this.stateChange$.next({ | ||
value: this.value, | ||
disabled: this._disabled | ||
}); | ||
} | ||
} | ||
|
||
constructor(public elementRef: ElementRef) { | ||
private _isDisabled(value) { | ||
return value != null && `${value}` !== 'false'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters