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

List element update not detected #757

Closed
chalin opened this issue Mar 18, 2014 · 5 comments
Closed

List element update not detected #757

chalin opened this issue Mar 18, 2014 · 5 comments

Comments

@chalin
Copy link
Contributor

chalin commented Mar 18, 2014

I am having a problem with list updates not being detected. The simplest example I could think of is given below. If you click on the list[0]=9 button, nothing happens:

image

Click on Add to list and then the 9 value appears along with the new list element.

image

This was run on HEAD (5b70fcc).

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>List update not working</title>
</head>
<body>
  <p>list = {{ list }} of length {{ list.length }}</p>

  <button ng-click='list[0]=9'>list[0] = 9</button>
  <button ng-click='list.add(list.length)'>Add to list</button>

  <script type="application/dart">
  import 'package:angular/angular.dart';
  void main() { ngBootstrap(module: new Module()..type(MyController)); }

  @NgController(selector: 'body', publishAs: 'ctrl')
  class MyController {
    MyController(Scope scope) { scope.context['list'] = [0,1,2]; }
  }
  </script>
  <script src="packages/browser/dart.js"></script>
</body>
</html>

Here is a scope_spec.dart test that illustrates the failure:

      iit('should watch list elt update', (Logger logger, Map context, RootScope rootScope) {
        context['list'] = [true, 2, 'abc'];
        rootScope.watch('list', (value, _) => logger(value));
        rootScope.digest();
        expect(logger).toEqual([[true, 2, 'abc']]);
        logger.clear();
        context['list'][2] = 'def';
        rootScope.digest();
        expect(logger).toEqual([[true, 2, 'def']]);
      });
@vicb
Copy link
Contributor

vicb commented Mar 18, 2014

@chalin I think there is a duplicate either in this tracker or on the ml. Could you please find it and reference it here. Thanks.

@chalin
Copy link
Contributor Author

chalin commented Mar 18, 2014

I searched the tracker before opening this one and did not find it (searched for anything related to 'list') ... because I also have the vague impression of seeing something like this being reported.

@vicb
Copy link
Contributor

vicb commented Mar 18, 2014

@chalin
Copy link
Contributor Author

chalin commented Mar 18, 2014

In the post the complaint was that list update was not detected, but that works in my example. On the other hand, individual element update does not. In both cases of my example (list[0] = 9 and Add to list) the identity of the list is not changed, so why is the behavior different? Shouldn't the list change detection behave the same for both?

@vicb
Copy link
Contributor

vicb commented Mar 18, 2014

to me it looks like a duplicate, ie the identity is not change when setting [0]
When list.length changes, the whole text is re-evaluated.
you should try <p><span>list = {{ list }}</span> of <span>length {{ list.length }}</span></p>

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