Within my web application, there exist two distinct user types: guests and logged users. Regardless of the user type, both are presented with identical content on the main page.
The objective :
- Upon a registered user clicking a link, 2 ajax requests ($http) will be made to fetch data from another page and display it in a model.
- If the user is a guest, a separate model will prompt them to register.
The link I have created :
<h4 ng-click="guestAction($event, showOne($event,card.id));">click me</h4>
GuestAction function :
$scope.guestAction = function($event, callbackB) {
$http.get('/guest/is-guest/').success(function(data) {
console.log("isGuest retrieved : " + data);
if (data == 1)
{
alert('guest spotted !');
return false;
}
else
{
alert('user');
console.log(callbackB);
eval('$scope.'+callbackB);
}
});
}
This approach ensures that if a guest is detected, the execution is halted by returning false. Conversely, for a regular user, the function showOne is executed. To manage consecutively fired asynchronous requests, I opted for the callback method.
An issue arises when showOne()
is triggered instantly upon ng-click activation. I attempted passing showOne()
as a string and utilizing eval()
within GuestAction
; however, the parameters were found to be undefined...
Are there any suggestions for resolving this dilemma? I aim to implement a universal procedure that triggers a function exclusively if the user is logged in.