Ron Thomson Ron Thomson - 1 year ago 103
AngularJS Question

How to check if $routeParams data exists

I'm trying to see if there is a way to redirect or perform any action based upon data existing at firebase location using routeParams in angularfire. If I have a user profile $routeParam setup, and the user object exists for user1,(users/user1), I would like to display that profile. However, if the user object doesn't exist for user20, instead of showing the template page with blank data, I would like to redirect to another page. I'm not sure where to make this call.
Here is my Profile Controller setup

function ($scope, $routeParams, User) {
$scope.user = User.findUsername($routeParams.username);

and my User Service for checking if the user exists

findUsername: function (username) {
if (username) {
return users.$child(username);

Answer Source

How about:

    function ($scope, $routeParams, User,$location) {

    $scope.user = User.findUsername($routeParams.username);

If you mean if you want to check if the username is a valid one, the only way to do so is through some check, ideally server side with $http. I would suggest making a service to check the server for valid usernames.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download