Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: url parameters for routing

I would like to use url parameters for routing in angularjs

I have an anguar app with 2 views : editView and mainView

Given a url that looks like this: 'httx://myapp/?param1=x&...&editmode=1&...'

-> will get me to the /editMode Path

What would be a good way to do so?

  • would i need to use a controller to get the $routeparams.editmode and use the $location.path('/editmode') if editmode == 1 ?
  • do i need html5 mode?

  • There is nothing i can do about the url - i am forced to use the editmode parameter


$routeProvider.when('/', {
  controller: function($routeParams, $location) {
    if($routeParams.editmode == '1') {
      $location.path('editMode') ...
like image 717
Thomas Deutsch Avatar asked Feb 23 '13 11:02

Thomas Deutsch


People also ask

What is $routeParams in AngularJS?

Overview. The $routeParams service allows you to retrieve the current set of route parameters. Requires the ngRoute module to be installed. The route parameters are a combination of $location 's search() and path() . The path parameters are extracted when the $route path is matched.

What is route parameters in angular?

To access the route parameters, we use route. snapshot , which is the ActivatedRouteSnapshot that contains information about the active route at that particular moment in time. The URL that matches the route provides the productId . Angular uses the productId to display the details for each unique product.

How does AngularJS routing work?

Routing in AngularJS is used when the user wants to navigate to different pages in an application but still wants it to be a single page application. AngularJS routes enable the user to create different URLs for different content in an application.

Which angular package is used to route to URL?

Generate an application with routing enabledlink The following command uses the Angular CLI to generate a basic Angular application with an application routing module, called AppRoutingModule , which is an NgModule where you can configure your routes.


1 Answers

I found out that "resolve:" instead of "controller:" was what i needed. If anyone is interested in changing routes via params, this is the way to go: https://github.com/angular/angular.js/issues/1838#issuecomment-13994168

like image 146
Thomas Deutsch Avatar answered Oct 13 '22 00:10

Thomas Deutsch