aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIgor Minar2012-05-02 00:33:00 -0700
committerIgor Minar2012-05-02 14:24:43 -0700
commit3bd3cc571dcd721f9d71f971aefee23115a5e458 (patch)
tree015d9745865329ab5feca8780ef85f9f95aab498 /src
parentc7f11015205835e83d935417e3342a18fe23c3fa (diff)
downloadangular.js-3bd3cc571dcd721f9d71f971aefee23115a5e458.tar.bz2
fix(select): don't interfere with selection if not databound
Closes #926
Diffstat (limited to 'src')
-rw-r--r--src/ng/directive/select.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js
index aa540828..dda59375 100644
--- a/src/ng/directive/select.js
+++ b/src/ng/directive/select.js
@@ -126,13 +126,17 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
return {
restrict: 'E',
require: ['select', '?ngModel'],
- controller: ['$element', '$scope', function($element, $scope) {
+ controller: ['$element', '$scope', '$attrs', function($element, $scope, $attrs) {
var self = this,
optionsMap = {},
ngModelCtrl = nullModelCtrl,
nullOption,
unknownOption;
+
+ self.databound = $attrs.ngModel;
+
+
self.init = function(ngModelCtrl_, nullOption_, unknownOption_) {
ngModelCtrl = ngModelCtrl_;
nullOption = nullOption_;
@@ -509,6 +513,11 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) {
}];
var optionDirective = ['$interpolate', function($interpolate) {
+ var nullSelectCtrl = {
+ addOption: noop,
+ removeOption: noop
+ };
+
return {
restrict: 'E',
priority: 100,
@@ -521,11 +530,15 @@ var optionDirective = ['$interpolate', function($interpolate) {
}
}
- // For some reason Opera defaults to true and if not overridden this messes up the repeater.
- // We don't want the view to drive the initialization of the model anyway.
- element.prop('selected', false);
-
return function (scope, element, attr, selectCtrl) {
+ if (selectCtrl.databound) {
+ // For some reason Opera defaults to true and if not overridden this messes up the repeater.
+ // We don't want the view to drive the initialization of the model anyway.
+ element.prop('selected', false);
+ } else {
+ selectCtrl = nullSelectCtrl;
+ }
+
if (interpolateFn) {
scope.$watch(interpolateFn, function(newVal, oldVal) {
attr.$set('value', newVal);