Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Commit

Permalink
fixed ngModel binding issue in select component and update documentat…
Browse files Browse the repository at this point in the history
…ion of colorpicker component.
  • Loading branch information
dharmeshpipariya committed Jun 15, 2016
1 parent d21d8f5 commit 338e98d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
19 changes: 18 additions & 1 deletion src/components/colorpicker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@ Example:

```html
//HTML

<input [(colorpicker)]="color"
position="right"
offset="0"
format="hex"
[style.background]="color"
[value]="color"
(change)="change($event)" />

//--- or ---

<div [(colorpicker)]="color"
position="right"
offset="0"
format="hex">
format="hex"
[style.background]="color"
(change)="change($event)">
</div>
```
```ts
Expand All @@ -32,6 +45,10 @@ export class ... {

private color: string = "#123456";

private change(value) {
...
}

...

}
Expand Down
33 changes: 32 additions & 1 deletion src/components/select/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,43 @@ export class Md2Select implements AfterContentInit, AfterContentChecked, Control
}

ngAfterContentChecked() {
let opt = this._options.filter(o => o.value == this.value)[0];
let opt = this._options.filter((o) => {
//let o1 = o.value, o2 = this.value;
//if (o.value == this.value) return true;
//if (o1 === null || o2 === null) return false;
//if (o1 !== o1 && o2 !== o2) return true;
//let t1 = typeof o1, t2 = typeof o2;
//if (t1 === t2 && t1 === 'object') {
// if (JSON.stringify(o1) === JSON.stringify(o2)) return true;
// else return false;
//}
//return false;
return this.equals(o.value, this.value);
})[0];
if (opt) {
this.selectedValue = document.getElementById(opt.id).innerHTML;
}
}

private equals(o1, o2) {
if (o1 === o2) return true;
if (o1 === null || o2 === null) return false;
if (o1 !== o1 && o2 !== o2) return true;
let t1 = typeof o1, t2 = typeof o2, length, key, keySet;
if (t1 === t2 && t1 === 'object') {
keySet = Object.create(null);
for (key in o1) {
if (!this.equals(o1[key], o2[key])) return false;
keySet[key] = true;
}
for (key in o2) {
if (!(key in keySet) && key.charAt(0) !== '$' && o2[key]) return false;
}
return true;
}
return false;
}

@HostListener('click', ['$event'])
public onClick(e: any) {
if (this.disabled) {
Expand Down

0 comments on commit 338e98d

Please sign in to comment.