I need to access a scope variable within a directive as a JavaScript variable. Here is the code snippet:
app.controller("Home", ["$scope", function($scope) {
...
$scope.nb_msg = data.length;
...
}]);
app.directive("myDiv", function() {
// In this section, I am trying to retrieve $scope.nb_msg
var nb_msg = ???;
var result = [];
// Perform operations on nb_msg to generate a result
var template = "";
...
for(var i=0; i<10; i++) {
template += "<span>" + result[i] + "</span>";
}
...
return {
restrict: "E",
template: template
};
});
Any suggestions on how to achieve this task? Your help would be greatly appreciated!