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].
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.

Reply via email to