There is a template that is displayed on different pages (under different url). There is a line in the template:
<li ng-repeat="user in vm.getLawyers()"><a ng-click="vm.TicketUserFilter(user)" href=""><ticket-lawyer-label lawyer="user"></ticket-lawyer-label></a></li> There are problems with the vm.getLawyers () function. This function should display a list of users sorted by groups. Here is the js code where users are sampled:
$scope.$watch("vm.team.id", function(teamId) { return User.getList({ profile__is_lawyer: "True", teams: teamId }).then(function(data) { vm.lawyers = data; return console.log(teamId); }); }); the problem in teams: teamId, on some pages this condition is fulfilled, and on others teamId is defined as undefined and users are displayed in an array, without sampling. Can someone tell me what the problem may be, in which direction to dig. In general, see the vm.getLawyers () function on coffee
vm.getLawyers = -> if vm.lawyers and vm.currentLawyer return (lawyer for lawyer in vm.lawyers when lawyer.id isnt vm.currentLawyer.id) else return vm.lawyers a vm.lawyers we get from here:
$scope.$watch "vm.team.id", (teamId) -> User.getList(profile__is_lawyer: "True", teams: teamId).then (data) -> vm.lawyers = data The router is:
app = angular.module "adherents.routes", [ "niz.djangoStatic", "ngRoute" ] # # === ROUTING === # app.config ["$routeProvider", "djangoStatic", ($routeProvider, djangoStatic) -> $routeProvider .when "/adherent/:adherentId", templateUrl: djangoStatic "adherents/partials/wks-adherent.html" # это страница где не определяется team title: "adhérent" controller: "AdherentCtrl" .................. ................. .when "/inbox", templateUrl: djangoStatic "adherents/partials/inbox.html" # это страница где определяется title: "boite de réception" ....................... ....................... .otherwise "/inbox" ] # Set title based on route app.run ["$rootScope", "$route", ($rootScope, $route) -> $rootScope.$on "$routeChangeSuccess", (currentRoute, previousRoute) -> $rootScope.title = $route.current.title ] and the AdherentCtrl controller is:
# controller for the adherent (wks) page app.controller "AdherentCtrl", ["$scope", "$routeParams", "ConversationViewer", "Adherent", "News", "Contact", "Search", "Restangular", ($scope, $routeParams, ConversationViewer, Adherent, News, Contact, Search, Restangular) -> adhId = $routeParams.adherentId $scope.ConversationViewer = ConversationViewer $scope.showEmail = ConversationViewer.show $scope.libraryFilter = from_adherent: adhId # no filter by team: wks adherent is global #$scope.$watch "main.currentTeam.id", (teamId) -> # $scope.libraryFilter.team = teamId $scope.ticketFilter = adherent: adhId # no filter by team: wks adherent is global #$scope.$watch "main.currentTeam.id", (teamId) -> # $scope.ticketFilter.team = teamId # bookmark or unbookmark the adherent $scope.toggleFavorite = -> method = if $scope.adherent.favorite then "unbookmark" else "bookmark" Adherent.one(adhId).all(method).post().then (data) -> $scope.adherent.favorite = data.favorite $scope.main.loadFavorites() # get the selected adherent data Adherent.get(adhId, log_access: "True").then (data) -> $scope.adherent = data $scope.main.loadLast() # reload last open wks adherent # get contacts Contact.getList(adherent: adhId).then (data) -> $scope.contacts = data # create a new contact $scope.newContact = -> contact = adherent_id: $scope.adherent.id Restangular.restangularizeElement(null, contact, "contact") $scope.contacts.push contact # function to save a contact and update ID $scope.saveContact = (contact) -> contact.save().then (data) -> Restangular.copy(data, contact) # find contacts for import $scope.findContacts = (query) -> Contact.getList(search: query, adherent_isnull: "True", limit:20) # add (import) a contact found by the typeahead $scope.addContact = -> contact = $scope.imported.contact contact.adherent_id = $scope.adherent.id $scope.saveContact contact $scope.contacts.push contact $scope.imported.contact = null # get + refresh news refreshNews = -> News.getList(adherent: adhId).then (data) -> $scope.news = data refreshNews() News.options().then (data) -> $scope.newsOptions = data # news form $scope.resetNewsForm = () -> $scope.newNews = adherent: adhId expires: null # manage news $scope.resetNewsForm() $scope.submitNewsForm = () -> postitem = angular.copy $scope.newNews if postitem.expires postitem.expires = postitem.expires.format "YYYY-MM-DD" News.post(postitem).then (data) -> refreshNews() # save the adherent data $scope.saveAdherent = -> adh = $scope.adherent adh.save() # execute search $scope.$watch "searchTerm", -> if $scope.searchTerm $scope.adhActTabs = 'aaT4' ]
$watch, secondly - it’s worth reading the help on this function , and what parameters it sends to the callback - Grundy