I'm trying to get a certain object out of an array of objects, that meets a certain criteria.
The id of the object should equal the scope variable $scope.lobbyid. My current approach below does not pass the lobby object into the controller.
the selected lobby represents the data of the active tab on the site. so the container array is fetched only once on site load.
markup
<div ng-repeat="lobby in lobbies | filter:checkLobbyID(lobby)">
[[lobby.name]]
</div>
controller
$scope.checkLobbyID = function($lobby) {
return $lobby.lobbyid == $scope.lobbyid;
}
array
"lobbies": [
{
"isglobal": true,
"lobbyid": 1,
"name": "GLOBAL",
},
{
"isglobal": false,
"lobbyid": 2,
"name": "stackoverflow rules",
},
{
"isglobal": false,
"lobbyid": 3,
"name": "sdadadad",
}
]
a temporary solution is to add the following code to the tab-switch event. but this needs a copy and another scope variable. how to achieve this with a filter?
angular.forEach($scope.lobbies, function(lobby) {
if (lobby.lobbyid == $scope.lobbyid)
$scope.currLobby = angular.copy(lobby);
});
ng-repeat?