Within the following code, I am utilizing a server method called "getUserNames()" that returns a JSON and then assigning it to the main.teamMembers variable. There is also a viewAll button included in a report that I am constructing, which triggers the method "$scope.viewAllTeamMembers = function($event)" as shown below.
The issue I am facing is that initially, the view all button does not display all the values stored in main.teamMembers when the report is first loaded. However, if I navigate to other buttons within the report and return to the viewAll button, it works as expected.
I have noticed that when the JSON is returned from an anonymous source rather than a global variable, the viewAll button functions correctly on the first attempt. I would appreciate your insights on what might be causing this discrepancy.
angular.module('kamApp')
.controller('MainCtrl', [
'$q',
'$rootScope',
'$scope',
'$timeout',
'endpoints',
'kamService',
'queries',
'translations',
function($q, $rootScope, $scope, $timeout, endpoints, kamService, queries, translations) {
var getUserNamesRequest = endpoints.getUserNames($rootScope.teamMemberIds).then(function(userData){
return userData;
});
getUserNamesRequest.then(function(userData,$scope) {
$rootScope.userNameList = kamService.extractUserNameList(userData);
main.teamMembers=kamService.concatTeamMemberName(
main.teamMembersData,
$rootScope.userNameList.list
);
main.teamMembers.list = kamService.sortList(main.teamMembers.list, 'role', 'name');
});
}]);
--Directive
angular.module('kamApp')
.directive('teamMember', function() {
return {
templateUrl: 'views/team-member.html',
replace: true,
restrict: 'E',
scope: {
teamMembers: '=',
viewSwitch: '=',
changeReportTitle: '&'
},
link: function($scope) {
$scope.itemLimit = 4;
$scope.isOddLength = $scope.teamMembers.list.length % 2 !== 0;
$scope.viewAllTeamMembers = function($event) {
$event.target.style.opacity = 0.6;
$scope.viewSwitch.dashboard = false;
$scope.viewSwitch.teamMember = true;
$scope.changeReportTitle()($scope.teamMembers.objectName.plural);
};
}
};
});
--HTML Code
"<div class=\"expand-link inline-block-div\" ng-click=\"viewAllTeamMembers($event)\"> \n"+