Kris Ivanov @CraftTek
12/11/2015
var app = angular.module('myApp', []);
app.directive('counter', function () {
return {
scope: {},
controller: function ($scope) {
$scope.counter = 0;
this.add = function () {
$scope.counter++;
};
this.subtract = function () {
$scope.counter--;
};
},
link: function (scope, element) {
}
};
});
app.directive('adder', function () {
return {
require: 'counter',
link: function (scope, element, attrs,
counterCtrl) {
counterCtrl.add();
}
};
});
app.directive('subtractor', function () {
return {
require: 'counter',
link: function (scope, element, attrs,
counterCtrl) {
counterCtrl.subtract();
}
};
});
Q & A