Skip to content

Instantly share code, notes, and snippets.

@think2011
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save think2011/16829f342e83d001dd12 to your computer and use it in GitHub Desktop.
Save think2011/16829f342e83d001dd12 to your computer and use it in GitHub Desktop.
ng-tools
(function() {
var app = angular.module('tools', []);
/**
* syncCheckboxModalToArray
* @$scope
* @modal string
* @array string
*/
app.factory('syncCheckboxModalToArray', function() {
return function($scope, modal, array) {
var $modal = eval('$scope.' + modal),
$array = eval('$scope.' + array);
$scope.$watch(modal, function(newV) {
var p;
$array.length = 0;
for(p in newV) {
if(newV[p]) $array.push(p);
}
}, true);
$scope.$watch(array, function(newV) {
var p;
for(p in $modal) {
$modal[p] = false;
}
newV && newV.forEach(function(v) {
$modal[v] = true;
});
}, true);
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment