0

I am new to angular JS. I am gradually learning it and finding it interesting.

I have a "Login" html page and a "Home" html page. "Home" html page displays navigation menu that open up other html pages.

Same ng-app and ng-controller (see below code) are declared in both "Login" html page and "Home" html page. (Both are using same angular module js.)

<html lang="en" ng-app="demoAppModule" ng-controller="DemoAppController">

I am opening up "Home" html page when user is successfully authenticated in Login controller (js).

To open the "Home" html page I am using $window.open() in Login controller (js). I am passing the loginid as query string (see below code) along with the "Home" html URL.

$window.open("http://localhost:8083/home.html?loginid=" + loginid, "_self");

How to retrieve the loginid from query string in the Home controller js?

2
  • did you try using window.location to fetch the url then extract loginid from it Commented Dec 3, 2019 at 9:33
  • share more code related to controller of home.html Commented Dec 3, 2019 at 9:34

2 Answers 2

1

in your Home-controller.js

try doing

var url = new URL(window.location.toString()); var loginId = url.searchParams.get("loginid");//metion your search param name as is in url

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

Comments

0

Since you are using angularjs you can make use of $location or $window services.

function homeController($scope, $location) {

   console.log($location.search().loginid);
}

2 Comments

Console log shows "undefined". The solution given below worked for me.
Oh okay :) There might be some issue, Here is the working demo - embed.plnkr.co/KzcMJmDGfN263AQrVY9N

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.