0

I have a single page webapp where any request that begins with request for e.g. http://localhost/appname/request* , the home page is sent back to the client using IIS URL rewrite module.

When Angular receives the webpage, it sees the route. I need to make sure Angular picksup up the routeParams.

Client request : http://localhost/appname/request/param1/param2

$routeProvider.when('/request/:param1/:param2',{
    templateUrl : 'app/views/myView.html',
    controller : 'MyCtrl',
    caseInsensitiveMatch : true
});
$routeProvider.otherwise({ redirectTo: '/' , caseInsensitiveMatch : true });     

$locationProvider.html5Mode(true).hashPrefix('!');

The controller listens to $routeChangeSuccess.

app.controller('MyCtrl',function($scope){
    $scope.$on('$routeChangeSuccess',function(event,routeData,$timeout,$rootScope){
     //routeData.pathParams are blank    
    });    
});

Also the URL changes to home page. I.e. I am redirected to http://localhost/appname.

What I am doing wrong?

1 Answer 1

1

If I understand correctly, you want to get the route params but the correct way to do this is by injecting $routeParams into the controller:

app.controller('MyCtrl',function($scope, $routeParams){
    if($routeParams.param1){
        alert('SUPER FLY!');
    }

});

http://docs.angularjs.org/tutorial/step_07

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

2 Comments

If you are tryinng to use html 5 mode, check this out: stackoverflow.com/questions/16677528/…
Thanks. The reason I was redirected was because of the otherwise rule. I haven't really made any changes but its working now. Also I didn't have to pass $routeParams along with $scope. I used $scope.$on('$routeChangeSuccess', function(event, routeData){}); inside my Myctrl.

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.