Directive's controller setter called before class instantiation (view attributes assigned before initialization) #13590
Description
This seems to be intentional in order to allow access to bound variables during a directive's controller instantiation, but it is really unintuitive.
As you can see in this codepen this can cause issues with variables that should have been instantiated in the constructor not being available when a method is called.
Basically in my situation we have a controller that needs to notify its link function when a bound variable is changed (widget.title), to do this I set up a setter for the variable that calls notify when it is called.
So the parent directive can change the title, then the setter is called which notifies the widget's link function. Although since the parentDir changes the title in it's constructor we get a console error where notify is called before the array of subscribers is set up. You can uncomment the code to see the order of the console logs. This code would allow my version to work, although it would end up masking other issues.
The code responsible for this is here
Following this pattern:
var instance = Object.create(directiveDefinition.controller.prototype);
instance.widgetTitle = "New Title"
directiveDefinition.controller.apply(instance);
Is there an existing pattern for getting around this issue? Seems sort of like a bug, although it would probably require a pretty big breaking change that would make a lot of people angry.