Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

One-way bindings of arrays behave inconsistently when a default value is set in the constructor #15118

Closed
@donmccurdy

Description

@donmccurdy

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?

One-way bindings of arrays behave inconsistently when a default value is set in the constructor.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).

Minimal JSFiddle example.

childCtrl.list2 is set but childCtrl.list1 never is. The changes argument to $onChanges(changes) contains both values, however.

What is the expected behavior?

Perhaps I made a terrible mistake by trying to set default values (list1=[] and list2=[]) in my child controller's constructor. Probably that's my fault, and list1 being empty is expected. But the problem did take me longer to track down because some previous code (like list2) had worked just fine.

What is the motivation / use case for changing the behavior?

I'd have expected list1 and list2 to behave the same way here. If setting a default in the constructor is bad and should never be done, then maybe no change is needed.

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.

v1.5.8, v1.5.9

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions