javascript - Getters and Setters on angular.extend $scope -


i'm reading interesting article angularjs: tricks angular.extend(), , there explained how use getters , setters extend. there points don't understand.

js:

app.controller('thingcontroller', [ '$scope', function($scope) {      // private     var _thingone = 'one',         _thingtwo = 'two';      // models     angular.extend($scope, {         thingone() {             console.log("get thing1");             return _thingone + 'eeeeee';         },         set thingone(value) {             console.log("set thing 1");             if (value !== 'one' && value !== 'two'){                 throw new error('invalid value ('+value+') thingone');            }         },         thingtwo() {             console.log("get thing2");             return _thingtwo + 'oooooo';         },         set thingtwo(value) {             console.log("set thing 2");             if (value !== 'two' && value !== 'three'){                 throw new error('invalid value ('+value+') thingtwo');            }         }    });      // methods     angular.extend($scope, {        things() {             return _thingone + ' ' + _thingtwo;         }     });  }]); 

html:

<body ng-controller="thingcontroller">     {{ things }} // one, 2  </body> 

my questions:

  1. ¿why on get thingone() not returned oneeeeeee? (the same get thingtwo())

  2. ¿where called set thingone , set thingtwo? because never see on console set thing 1 or set thing 2.

  3. ¿how can declare set method inside angular.extend methods? ¿it possible assing value view?

try way:

angular.extend($scope, {     things() {         return $scope.thingone + ' ' + $scope.thingtwo;     } }); 

setter called in case:

$scope.thingone = 'test'; 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -