Angular: Empty Fiddle
http://angularjs.org/
HTML
<script src="https://code.angularjs.org/1.5.2/angular.js"></script>
<div ng-app="myApp">
<div ng-controller="myCtrl">
<counter model2="count1"></counter>
</div>
</div>
JavaScript
var app = angular.module('myApp', [])
app.directive('counter',
function($timeout) {
return {
restrict: 'EAC',
template: `<div>Directive Counter: {{internalCount}}</div>`,
scope: {
internalCount: '=model2'
},
//link: function() {
// console.log("linker callled...");
//},
compile: function($scope, element) {
return function(scope, element, attrs) { // this is post-link function
function addCount() {
$timeout(function() {
scope.internalCount += 1;
addCount();
}, 1000)
}
scope.$watch('internalCount', function() {
console.log("hrruy!!!");
console.log(scope.internalCount);
});
addCount();
}
}
};
}
)
app.controller('myCtrl', function($scope) {
$scope.count1 = 10;
});