6

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') ...
4
  • Looks like you have server providing search params. Angular Routes parse the url hash, not search. Why do you need both methods? Commented Feb 23, 2013 at 14:27
  • I work with SharePoint 2013 apps and my angular app gets called like this: src="~appWebUrl/Pages/DemoPage.aspx?{StandardTokens}&wpId=_WPID_&editmode=_editMode_&wpq=_WPQ_&weblocaleId=_WebLocaleId_" where appWebUrl is a link to the "app-Web" and {standartTokens} resolves to a bunch of parameters Commented Feb 23, 2013 at 16:03
  • ok...so your asp outputs dynamic js based on url params? Should be able to just add $scope.editMode= <%aspcode%>...couldn't you? Commented Feb 23, 2013 at 16:12
  • in my controller i can add: if($routeParams.editMode == '1') { $location.path(editMode)} ... but is this the way to go? Commented Feb 23, 2013 at 17:05

1 Answer 1

3

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.