Probably the naming of this function is worng and there should be 2 functions here. Once we list the menu for the first time, we do not know in the $scope yet which item is current. So, this code is used to remember it. Should I separate this into 2 methods to make it more clear to read?