So I've been making progress on a problem I've been having but I'm not sure where to go from here.
In my code I have a module, and then a directive outside of the modules on its own, but it is injected.
I have an object called registrants
, in the parent scope. When I kick in the directive, any activity in the directive modifies the parent scope and registrants
will update. However, I have another variable registrantCount
that should be updating as the registrant list length increases but it isn't. Can someone explain to me why?
Here is the snippet of my code that contains all the relevant peices below, if there is a variable that is shown that I didn't mention in the description above, assume the data is correct for it, for the sake of completion. The only variables I am concerned with are the two I mentioned in my initial problem statement.
module
angular.module('register', [])
.controller('Register', function($scope, $rootScope, $http){
$scope.registrants = {};
$scope.registrantCount = 0;
$http({
url : 'apiLink for initial data'
}).then(function(data){
$scope.employeeList = data.data.payload[0]; // initial list to allow the directive to function
});
});
directive
angular.module('register.check', [])
.directive('attendees', function($http){
return {
restrict : 'EA',
scope : false,
templateUrl : 'template',
link : function(scope, elem, attrs){
angular.forEach(companies, function(c, key){
if(c.companyID == id){
scope.registrants = c.registrants; // this object is modified in the directive template
scope.registrantCount = scope.registrants.length; // this variable is located in the parent template, not the directive template
}
});
})
};
});
Again please note that the directive will modify the parent scope object of registrants but it will not modify the registrant count, nor will it generate a correct length in the parent variable if i modify it in the directive. I am very confused on this matter. Thank you for all the help ahead of time!