I know there is a way to make directives communicate with each other. You can do it through using controllers. My problem is I have 2 directives on the page I am creating a upload app, I am using a file change directive that detects whether or not a file input has been used to select a file and a directive that creates a dropzone for dragging and dropping files both are working.
But how do I make the app detect whether the dropzone or filechange directive are being used on the page I created a factory method and am using a a data service with an array to push the names of the directives into the array. but when it does even though both are on the page only one is registering? how do I fix this? is it an async issue?
here is my uploader3.js
var app = angular.module("uploader", []);
app.factory('data', function(){
return {
directives:[],
progressBarSet:false,
getData:function(){
return this;
}
}
});
app.directive("dropzone", ["data", function (data) {
return {
restrict: "A",
controller: function($scope){
},
priority: 0,
link: function (scope, element, attr, ctrl) {
data.directives.push("dropzone");
console.log(data.directives);
}
}
}]);
app.directive("filechange", ["data", function (data) {
return {
restrict: "A",
controller: function($scope){
},
priority: 1,
link: function (scope, element, attr, ctrl) {
data.directives.push("filechange");
console.log(data.directives);
}
}
}]);
here is my html.
<!doctype html>
<html ng-app="uploader">
<script src="Scripts/angular.min.js"></script>
<script src="app/uploader3.js"></script>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body dropzone>
<input type="file" name="FILEDATA" id="FILEDATA" accept="image/jpg, image/jpeg" filechange>
</body>
</html>
When I log the the data.directives it shows that I it has a length of 1? how do I apply the push and get both of the directives to register in my data service?
Is there a better way to figure out what directives are actually being applied on the page? I need to execute the next set of code based on whether or not the dropzone or file change directive has been implemented on the page, or if both are being used.