Within my application, there are two distinct types of profiles available for organisations. When a user interacts with a profile name, the system must first determine if a premium profile exists for that organisation. If a premium profile is found, the user will be directed to that specific profile. However, in cases where no premium profile is present, the user will be redirected to the standard profile.
To accomplish this functionality, I have implemented an ng-click event that passes the ID and resource parameters (in this case, 'organisation') to a controller. Within the controller, certain conditions are evaluated before routing the user appropriately. This process works seamlessly when a user clicks on a profile as intended.
The issue arises when a user attempts to open the link in a new tab by right-clicking and selecting that option. In such scenarios, the new tab opens with the URL of the current page, indicating that the ng-click event and controller logic have not executed prior to the tab opening.
How can I modify my code to ensure that Angular processes the ng-click request before allowing the new tab to open? Essentially, how can I enable users to open these links in new tabs without simply displaying the current page?
HTML
<div ng-controller="ProfileRouter">
<div ng-repeat="org in orgs | orderBy:'org.name'">
<a href="" ng-click="profileCheck( '{{ org.id }}', 'organisation' )">{{ org.name }}</a>
</div>
</div>
Inside the ProfileRouter controller:
$scope.profileCheck = function (id, resource) {
$http({method: 'GET', url:'/IdCheck', params:{'id': id})
.success(function(data) {
var count = data.hits.found;
if (count) {
var hash = data.hits.hit[0].id;
}
if (resource == 'organisation') {
theResource = 'universities';
page = 'overview';
}
if (count == 1) {
window.location.href = "/" + theResource + "/profile/" + hash + "/" + page;
}
if (count == 0) {
window.location.href = "/" + resource + "/" + id;
}
})
.error(function(data) {
$scope.data = data || "Can't get resource";
});
}