I'm trying to write a Directive to decode and encode some information. Basically I am storing 5 binary pieces of information in a database using an Int (giving each bit a value of 16, 8, 4, 2, 1).
I need to ways of editing the data: as an Int, and as bits. But I have lots of problems connecting them up, and these are (deliberately) compounded by using controllerAs notation.
1) When I change the Int nothing changes in the bits. This is because the link function only seems to load once - how can I have a change in a model update information in a Directive?
<input ng-model="c.int" type="text" />
<testdir score="c.int"></testdir>
My Directive includes:
scope: {
score: '='
},
controller: function() {
var vm = this;
vm.recChange = function() {
// convert bits to score
}
},
controllerAs: 'd',
link: function(scope, elem, attrs) {
// convert score to bits
and a link function that converts score into scope.recommendations, which is an array 5 bits.
2) When I change the bits (and have controllers using $scope) then the Int does change. But I cannot find a way to use controllerAs - the link function uses scope whereas my controller needs a d. prefix.
template: "<label ng-repeat='(key, recommendation) in recommendations' class='checkbox-inline'>
// template: "<label ng-repeat='(key, recommendation) in d.recommendations' class='checkbox-inline'> \