var app = angular.module("app",[]); app.controller("ColorController", function($scope){ $scope.convert = function(){ $scope.hex =("#").concat(Math.floor((Math.random() * 10000) + 1)) } }) app.directive("color", function() { return { restrict: 'E', scope: { do: '&' }, template: '<input type="text" ng-click="do()" /> {{hex}}' } });
<div ng-app="app"> <div ng-controller="ColorController"> Renk-1 <color do="convert()"></color>{{hex}}<br/> </div> </div>