Closed
Description
There's been quite a push for use of the controllerAs
syntax across the board, and while Classy mostly supports it just fine, there's a bit of a gotcha with the watch
section, as it binds onto the $scope
.
Current workarounds:
- Bind to
controllerName.property
. This requires hard-coding the name of the controller on the scope into the controller itself, making future renames (for whatever reason) a potential trap. - Assign the controller to
$scope
under a standard name (i.e.self
) and bind toself.property
. This works around the hard-coding issue, though introduces a peculiar assignment in each controller, and potentially some strange scoping in the case of nested controllers though I have not tested this situation as yet. - Manually bind using
$scope.$watch (=> @property), ...
(apologies for CS). This avoids both hard-coding and adding crap to the scope, but completely removes the benefits of using Classy's system.
Proposal:
The third workaround seems to be the cleanest solution, so I'd think it worth looking into if it could be incorporated in some manner. Without looking into it really deeply, I'd think that it would be safe to automatically switch handling of watch
to that implementation when addToScope
is false
- or potentially a separate config option.
Apologies if I've completely overlooked something obvious, I did check over what was around before writing this up but I may well have missed something.
Metadata
Metadata
Assignees
Labels
No labels