I've just successfully tried it on my one of my directives which looks just like yours and it works fine Can you paste the code that calls this directive? all you need to do is: '<appIcon type='some-type'></appIcon>' and the setter is called...
Another dynamic scenario is when you require this directive in another directive and call this api from that other directive, didn't test that... On Tuesday, February 3, 2015 at 6:28:49 PM UTC+2, Michael Thompson wrote: > > I've tried it with both with no luck. 'Intuitively' I would expect the > setter to be called on the controller regardless of @ or = binding, but > this doesn't appear to be the case. Thanks! > --m > > > On Tue, Feb 3, 2015 at 1:48 AM, Avi Engelshtein <[email protected] > <javascript:>> wrote: > >> The setter doesn't get called probably because you have defined the >> 'type' property as a one way binding with '@' which is just a string passed >> from the parent scope to the directive's isolated scope >> Change it to '=' to implement a 2 way binding and then the setter will be >> called >> >> >> On Monday, February 2, 2015 at 8:21:49 PM UTC+2, Michael Thompson wrote: >>> >>> All, attempting to use bindToController with Object.defineProperty so I >>> can provide a custom setter like this: >>> >>> (function() { >>> >>> angular.module('app.directives').directive('appIcon', appIcon); >>> >>> function appIcon() { >>> return { >>> restrict: 'E', >>> template: '<span ng-class="vm.iconClass"></span>', >>> scope: { >>> type: '@' >>> }, >>> controllerAs: 'vm', >>> bindToController: true, >>> controller: function() { >>> var _iconClass; >>> var _type; >>> >>> Object.defineProperty(this, 'type', { >>> configurable: false, >>> enumerable: true, >>> get: function() { >>> return _type; >>> }, >>> set: function(type) { >>> _type = type; >>> _iconClass = 'icon-' + _type; >>> } >>> }); >>> >>> Object.defineProperty(this, 'iconClass', { >>> configurable: false, >>> enumerable: true, >>> get: function() { >>> return _iconClass; >>> } >>> }); >>> } >>> })(); >>> >>> Problem is that my setter never seems to get called. The getters are >>> called and work just fine. If I flip some logic to just have the iconClass >>> getter always compute the _iconClass value this directive works. I'm >>> looking to implement something more complicated with multiple properties in >>> play though so being able to hook into the setter would be ideal. Will >>> that not work with the way that bindToController is implemented? Thanks! >>> --m >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "AngularJS" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at http://groups.google.com/group/angular. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
