Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Detaching <select> with [multiple] attribute results in an exception #428

Closed
ewenchou opened this issue Jan 22, 2014 · 0 comments
Closed
Milestone

Comments

@ewenchou
Copy link

This looks similar to Issue #392 except affects select inputs with the multiple attribute specified.

Using the same HTML code from Issue #392 with multiple attribute:

<button ng-click="attached = !attached">Toggle!</button>
<div ng-if="attached">
  <select ng-model="irrelevant" multiple>
    <option>foo</option>
    <option>bar</option>
  </select>
  </div>
</div>

Click the Toggle button and then select one or more values. Then click the Toggle button again will produce this error:

The null object does not have a getter 'ngValue'.

NoSuchMethodError : method not found: 'ngValue'
Receiver: null
Arguments: []

With the stacktrace:

STACKTRACE:
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      _MultipleSelectionMode.onModelChange.<anonymous closure> (package:angular/directive/input_select.dart:225:70)
#2      _SelectMode._forEachOption (package:angular/directive/input_select.dart:139:24)
#3      _MultipleSelectionMode.onModelChange (package:angular/directive/input_select.dart:228:19)
#4      InputSelectDirective.dirty.<anonymous closure> (package:angular/directive/input_select.dart:73:28)
#5      relaxFnArgs.<anonymous closure> (package:angular/utils.dart:66:40)
#6      Scope.$eval (package:angular/core/scope.dart:616:43)
#7      Scope._digestHandleQueue (package:angular/core/scope.dart:481:20)
#8      Scope._digestWhileDirtyLoop (package:angular/core/scope.dart:439:44)
#9      Scope.$digest (package:angular/core/scope.dart:415:28)
#10     _autoDigestOnTurnDone (package:angular/core/scope.dart:108:14)
#11     _rootRun (dart:async/zone.dart:688)
#12     _ZoneDelegate.run (dart:async/zone.dart:417)
#13     NgZone._finishTurn (package:angular/core/zone.dart:97:21)
#14     NgZone._onRunBase (package:angular/core/zone.dart:57:20)
#15     _onRunUnary (package:angular/core/zone.dart:66:22)
#16     _ZoneDelegate.runUnary (dart:async/zone.dart:426)
#17     _CustomizedZone.runUnary (dart:async/zone.dart:631)
#18     _BaseZone.runUnaryGuarded (dart:async/zone.dart:546)
#19     _BaseZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:572)

I did a really rough patch on _MultipleSelectionMode.onModelChange in directive/input_select.dart (see below). Seems to work in my limited testing.

onModelChange(List selectedValues) {
  Function fn = (o, i) => o.selected = null;

  if (selectedValues is List) {
    // ORIGINAL CODE
    // fn = (o, i) => o.selected = selectedValues.contains(expando[o].ngValue);

    // MY CODE
    fn = (o, i) {
      if (expando[o] != null) {
       o.selected = selectedValues.contains(expando[o].ngValue);
      } else {
        o.selected = false;
      }
    };
  }
@ghost ghost assigned mhevery Jan 27, 2014
@mhevery mhevery closed this as completed in 6228692 Feb 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants