Tream
Tream

Reputation: 1054

AngularJS: Pass Parameter through URL

I have a AngularJS Application in different languages.

Now I want to preselect a language, when the user calls the site, with following string at the end: /en, /de, ...

Is this even possible in AngularJS? I also can use some other syntax, if this is needed.

Thank you very much!

Upvotes: 0

Views: 133

Answers (2)

sethu
sethu

Reputation: 8411

With the limited amount I could understand from your question..

var app=angular.module("angularapp",['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
    .when('/',{
        redirectTo: '/en'
    })
    .when('/:language',{
        //do something
    });
}]);

you can then get access to {"language":"en"} object

Upvotes: 1

atmd
atmd

Reputation: 7490

If you are wanting to get something from the url to run logic on (i.e. /de in the url) you can use the $location object

Angular location

If you are wanting dynamic urls so that things like /de, /fr, /es go to the same page/view, you'll need to use the $route object

Angular routes

Upvotes: 1

Related Questions