When using AngularJS, I have a scenario where I am navigating a user to a page with a query string that is based on employees they selected on a previous page. In order to log the variable $scope.splitusers
, which contains an array of user.ID
s like ["14", "21"] passed from the previous page, I am splitting the query string. My goal is to utilize ng-if
to display a user's information in the HTML when user.ID == splitusers
in the JavaScript. This functionality works smoothly when there is only one user.ID
in the query string but breaks down when multiple users are selected.
Below is the section of HTML code that is currently causing issues:
<div ng-app="myApp">
<div ng-controller="MainCtrl">
<div class="ProfileSheet" ng-repeat="user in users" ng-if="user.ID == splitusers">
<table id="Profile">
<tr>
<th>User</th>
<td>{{user.Title}}</td>
</tr>
</table>
</div>
</div>
</div>
Here is the corresponding JS code:
var app = angular.module('myApp', ['ngSanitize']);
app.controller('MainCtrl', function($scope, $http, $q){
var getQueryString = function (field, url){
var href = url ? url : window.location.href;
var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
var string = reg.exec(href);
return string ? string[1] : null;
}
$scope.selectedusers = getQueryString('users', window.location.href)
$scope.splitusers = $scope.selectedusers.split(',')
});
Is there a way to resolve this issue?