Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit ed20a79

Browse files
committed
Render intial state correctly
Fixes #12
1 parent b5adc47 commit ed20a79

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/select.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ angular.module('ui.select', [])
5454
var ngModelCtrl = controllers[1];
5555

5656
scope.$watch('$select.selected',function(newVal,oldVal){
57-
ngModelCtrl.$setViewValue(newVal);
57+
if (ngModelCtrl.$viewValue != newVal) ngModelCtrl.$setViewValue(newVal);
5858
});
5959

60+
ngModelCtrl.$render = function() {
61+
scope.$select.selected = ngModelCtrl.$viewValue;
62+
};
63+
6064
$document.bind('click', function (evt) {
6165
if (angular.element(evt.target).hasClass('ui-select-search')){
6266
return;

test/select.spec.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('ui-select tests', function() {
3939
return element;
4040
};
4141

42-
it('should compile basic ui-select-* elements ', function() {
42+
it('should compile child directives', function() {
4343

4444
var el = uiSelectElInstance1();
4545

@@ -60,4 +60,15 @@ describe('ui-select tests', function() {
6060

6161
});
6262

63+
it('should correctly render initial state', function () {
64+
65+
scope.selection = scope.matches[0];
66+
67+
var el = uiSelectElInstance1();
68+
var matchLabel = $('.ui-select-match > div[ng-transclude]', el).text();
69+
70+
expect(matchLabel).toEqual('Wladimir Coka');
71+
72+
});
73+
6374
});

0 commit comments

Comments
 (0)