1

I am using AngularJS to create a Single Page Application (mobile app). The code below allowed me to successfully inject the home page with a login module upon click off a button:

$("#loginButton").click(function() {
  location.href='#login';
});

However, I later decided to automatically navigate the user to a login page if a login was not detected, and a navigation page if it was detected. When I switched to:

$(document).ready(function() {
  location.href='#login';
});

I received the following error:

TypeError: Cannot read property 'charAt' of undefined at Object.LocationHashbangUrl.$$parse (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js:8708:40)

I was wondering why I received this error, and what is the appropriate way to send a user to either 1 of 2 pages upon loading of the app.

1 Answer 1

1

The "Angular" way would be to use $location, like this:

$location.path('login');

Your error seems to be coming by using Angular's location service (not the native JS one, did you alias the Angular one?) with the syntax of the JS one.

Sign up to request clarification or add additional context in comments.

3 Comments

I put $location.path('login'); in the controller. I no longer get the error when testing localhost, but the error still appears when I run it on my Android device.
Are you sure you have the latest version on the Android? Because the device shouldn't matter.
I was using jQuery Mobile, which from what I just read could conflict with AngularJS. I removed the jQuery Mobile include, built and ran the app on my Android Device, and the appropriate login page loaded without error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.