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.

feature($compile): a switch to disable the old (pre-ES6) way to init bindings #14362

Closed
@thorn0

Description

@thorn0

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

feature

What is the current behavior?

From the docs for $compile:

Deprecation warning: although bindings for non-ES6 class controllers are currently bound to this before the controller constructor is called, this use is now deprecated. Please place initialization code that relies upon bindings inside a $onInit method on the controller, instead.

There is no possibility currently to disable this deprecated behavior.

What is the expected behavior?

$compileProvider.enableDeprecatedEarlyBinding(false) should turn off this behavior.

Or even better, if we could disable it on per-directive basis.

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

Because of this deprecated behavior, it's impossible to use simple property initializers in TypeScript to specify default values for properties that have optional bindings associated with them.

class Foo {
  binding = 2;
}

It looks nice and simple, but if the bound attribute exists, the default value overwrites the initial value of the binding. So for now, the initializers have to look unappealing like this:

class Foo {
  binding: number = this.binding || 2;
}

Also this won't really work for situations like boolean properties, empty strings as initial values of bindings, etc. And note that we had to specify the type as it can't be inferred from the self-referring initializer expression.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions