AngularJS - Simple Directive Use
HTML
<script src="http://code.angularjs.org/1.0.0/angular-1.0.0.js"></script>
<div ng-app="myApp">
<div ui-foo></div>
</div>
JavaScript
angular.module('ui.directives', []);
angular.module('ui.directives', []).directive('uiFoo',
function() {
return {
restrict: 'EAC',
require: '?ngModel',
link: function($scope, element, attrs, controller) {
$scope.updateUploadView =
{
ready:{
inview:false,
text: "files selected"
},
uploading:{
inview:false,
text: "files are getting uploaded"
},
done:{
inview:false,
text: "files uploaded perfectly !"
}
};
angular.forEach($scope.updateUploadView, function(element, key) {
$scope.$watch(function () {
return element;
}, function() {
console.log(key);
},true);
});
// here i want to start $watch to trigger
$scope.updateUploadView.inview = true;
}
};
}
);
angular.module('myApp', ['ui.directives']);