'uncaught Syntaxerror: Unexpected Token U' In Angularjs
I am getting Uncaught SyntaxError: Unexpected token u error on my login page. I am working with angularjs and localstorage. HTML
) ? JSON.parse($localStorage.getItem('user')) : undefined;
Some suggestions:
In your HTML
you have used ng-model
for the input
fields.
So you need not pass user
object to the login
method. By default, the values will be set in $scope.user.username
and $scope.user.password
.
so your login
method will become:
$scope.login = function (user) {
$localStorage.setItem('Login Details', JSON.stringify($scope.user));
// make sure it should be Login Details / uservar path = "layout.html";
$location.replace(path);
};
The problem is with localStorage.getItem("user")
. I don't see anywhere you are setting localStorage.setItem("user")
. Even in the login method you have localStorage.setItem("Login Details")
.
Solution 2:
You use a variable localStorage
instead of $localStorage
. Fix this, and tell us if you sill have your error.
Same problem with location
var (it must be $location
).
Post a Comment for "'uncaught Syntaxerror: Unexpected Token U' In Angularjs"