I have ten colors, I want to write a directive that shows 10 boxes with these colors and user picks one of these colors, I want it to be like this:
colors
is an array of colors in hex
Here is what I come up till now:
(function (angular) {
"use strict";
angular.module('color-picker', [])
.directive('colorPicker', function () {
return {
restrict: "E",
scope: {
colors: "="
},
templateUrl: "color-picker.html",
link: function (scope, elem, attrs) {
scope.setColor = function(color) {
scope.selectedColor = color;
}
}
}
})
})(angular);
and here is the template:
<div>
<div class="color-box" ng-repeat="color in colors">
<div class="color" ng-style="{'background-color': color}" ng-click="setColor(color)">
</div>
<div class="color-name text-center">
#{{color}}
</div>
</div>
</div>
what should I do in order to make it ngModel
wise? like a regular input with validation and data binding?