// The module
(function() {
angular.module('colorized', [])
.service('$colors', function() {
this.lighten = function(src, percent) {
var src = normalizeColor(src);
if (!percent) return src;
var srcRGB = colorAsArray(src),
lightFactor = (255 * percent) / 100,
newRGB = {
r: limited(srcRGB.r + lightFactor, 255),
g: limited(srcRGB.g + lightFactor, 255),
b: limited(srcRGB.b + lightFactor, 255),
};
return [
padRGBDigit(newRGB.r.toString(16)),
padRGBDigit(newRGB.g.toString(16)),
padRGBDigit(newRGB.b.toString(16))
].join('');
}
function normalizeColor(color) {
if (color == undefined) color = '000000';
if (color[0] == '#') color = color.substring(1);
return color;
}
function colorAsArray(color) {
return {
r: parseInt(color.substring(0, 2), 16),
g: parseInt(color.substring(2, 4), 16),
b: parseInt(color.substring(4, 8), 16),
};
}
function limited(value, limit) {
return Math.ceil(value > limit ? limit : value);
}
function padRGBDigit(str) {
return ('00' + str).slice(-2);
}
});
})();
// My App
(function() {
angular.module('myApp', ['colorized'])
.controller('myController', function($scope, $colors) {
$scope.mySourceColor = '#000000';
$scope.myPercentage = 50;
$scope.myLightColor = function() {
return '#' + $colors.lighten($scope.mySourceColor, $scope.myPercentage);
};
});
angular.element(document).ready(function() {
angular.bootstrap(document, ['myApp']);
});
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<div ng-controller="myController">
<input type="color" ng-model="mySourceColor">
<input ng-style="{'background-color': myLightColor()}" type="range" ng-model="myPercentage" min="0" max="100">
<span>
{{ myLightColor() }}
</span>
</div>