How to pass GET variable to angular app

I have a heroku app which is built with node.js and ionic / angular. The site url looks like

myapp.herokuapp.com

Since it is ionic / angular and relies on state and views when you enter a url, it takes you to the home page

myapp.herokuapp.com/www/index.html#/login

what well.

The problem is that I want to create personalized referrer links for third parties to send people to my application. In theory it would look like

myapp.herokuapp.com?ref=12345

The "ref" parameter is useful to me and I want to retrieve it when my first controller loads and bind it to a variable in the service. However, due to states and views, the url ends up

myapp.herokuapp.com/www/index.html?ref=12345#/login

by the time my first controller is on the login page.

The site still works like this, but I can't help but feel like I'm doing it wrong. There must be an angular way to extract the GET parameter from the url without any crazy string parsing and concatenation when my first controller is loaded.

+3


source to share


1 answer


If you are using routeProvider you can do something like this:

    $routeProvider
    .when('/Index', { templateUrl: baseUrl + "/Index" })
    .when('/Index/:parameter1/:parameter2/', {
        templateUrl: function (params) {
            return baseUrl + "/Index/GetSomething?idparameter1=" + params.parameter1+ "&idparameter2=" + params.parameter2;
        }
    })

      



I hope this can help you.

0


source







All Articles