Last active
August 29, 2015 14:22
-
-
Save think2011/16829f342e83d001dd12 to your computer and use it in GitHub Desktop.
ng-tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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