0 && itemObjects[0].hasChildren()"
+
`;
@Component({
- selector: 'ng-select',
+ selector: 'ng2-select',
pipes: [HighlightPipe],
template: `
(this.multiple === false ||
- this.multiple === true && !this.active.find(o => option.text === o.text)));
+ if (this.optionsOpened)
+ return;
+
+ this.populateOptions();
if (this.options.length > 0) {
this.behavior.first();
@@ -238,6 +249,12 @@ export class Select {
this.optionsOpened = true;
}
+
+ private populateOptions() {
+ this.options = this.itemObjects
+ .filter(option => (this.multiple === false ||
+ this.multiple === true && !this.active.find(o => option.text === o.text)));
+ }
ngOnInit() {
this.behavior = this.itemObjects[0].hasChildren() ?
@@ -263,7 +280,7 @@ export class Select {
return;
}
- if (e.srcElement.contains(context.element.nativeElement)
+ if (context.element.nativeElement.contains(e.srcElement)
&& e.srcElement && e.srcElement.className &&
e.srcElement.className.indexOf('ui-select') >= 0) {
if (e.target.nodeName !== 'INPUT') {
@@ -395,7 +412,8 @@ export class Select {
}
private selectActiveMatch() {
- this.selectMatch(this.activeOption);
+ if (this.options && this.options.length > 0)
+ this.selectMatch(this.activeOption);
}
private selectMatch(value:SelectItem, e:Event = null) {
@@ -405,7 +423,7 @@ export class Select {
}
if (this.options.length <= 0) {
- return;
+ this.populateOptions(); //load options, if they aren't yet populated
}
if (this.multiple === true) {
@@ -420,9 +438,11 @@ export class Select {
this.doEvent('selected', value);
this.hideOptions();
+ this.inputValue = ''; //clear highlight pipe match
if (this.multiple === true) {
this.focusToInput('');
+ this.open();
} else {
this.focusToInput( stripTags(value.text) );
this.element.nativeElement.querySelector('.ui-select-container').focus();
@@ -629,3 +649,4 @@ export class ChildrenBehavior extends Behavior implements IOptionsBehavior {
}
+