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

Commit 5de7121

Browse files
fix(typeahead): fix label rendering for equal model and items names
1 parent 64df05e commit 5de7121

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/typeahead/test/typeahead.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,14 @@ describe('typeahead tests', function () {
338338
var inputEl = findInput(prepareInputEl("<div><input ng-model='result' typeahead='state as state.name + \" \" + state.code for state in states | filter:$viewValue'></div>"));
339339
expect(inputEl.val()).toEqual('');
340340
});
341+
342+
it('issue 786 - name of internal model should not conflict with scope model name', function () {
343+
$scope.state = $scope.states[0];
344+
var element = prepareInputEl("<div><input ng-model='state' typeahead='state as state.name for state in states | filter:$viewValue'></div>");
345+
var inputEl = findInput(element);
346+
347+
expect(inputEl.val()).toEqual('Alaska');
348+
});
341349
});
342350

343351
describe('input formatting', function () {

src/typeahead/typeahead.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
172172
return inputFormatter(originalScope, locals);
173173

174174
} else {
175-
locals[parserResult.itemName] = modelValue;
176175

177176
//it might happen that we don't have enough info to properly render input value
178177
//we need to check for this situation and simply return model value if we can't apply custom formatting
178+
locals[parserResult.itemName] = modelValue;
179179
candidateViewValue = parserResult.viewMapper(originalScope, locals);
180-
emptyViewValue = parserResult.viewMapper(originalScope, {});
180+
locals[parserResult.itemName] = undefined;
181+
emptyViewValue = parserResult.viewMapper(originalScope, locals);
181182

182183
return candidateViewValue!== emptyViewValue ? candidateViewValue : modelValue;
183184
}

0 commit comments

Comments
 (0)