This worked for me with some minor tweaks in AngularJS 1.3.16. Asp.NET MVC is the server-side language used to build my template, but the idea of passing query string (or Search) parameters to the server is the same.
With these changes, if the user put the following Url into their browser: http://myExampleOrigin/page?foo=bar Then the request to asp.net MVC would be for the following: http://myExampleOrigin/MVC/page?foo=bar angular.module('app').controller('pageRouteCtrl', ['$scope', '$window' ,function($scope, $window){ $scope.templateUrl = "/MVC/page" + $window.location.search; }]); var module = angular.module('MyModule', [], function ($routeProvider) { var template = '<div ng-include="templateUrl">Loading...</div>'; //Changed : to = $routeProvider .when('/home', {templateUrl: 'home.php'}) .when('/page', {template: template, controller: 'pageRouteCtrl'}). //Deleted :someParam .otherwise({redirectTo:'/home'}); }); On Monday, May 27, 2013 at 4:07:37 AM UTC-5, Leo wrote: > > One option which might suit your requirements is to use a simple template > with an ng-include attribute. You then use a controller to populate the > include: > > angular.module('app').controller('pageRouteCtrl', ['$scope', > '$routeParams' ,function($scope, $routeParams){ > $scope.templateUrl = "/page/" + $routeParams.someParam; > }]); > > var module = angular.module('MyModule', [], function ($routeProvider) { > > var template: '<div ng-include="templateUrl">Loading...</div>'; > $routeProvider > .when('/home', {templateUrl: 'home.php'}) > .when('/page/:someParam', {template: template, controller: > 'pageRouteCtrl'}). > .otherwise({redirectTo:'/home'}); > }); > > > > On Saturday, May 25, 2013 12:56:25 AM UTC+8, Chris Staymates wrote: >> >> Suppose I have configured my route provider as such. There are no >> controllers configured in my route on purpose. >> >> var module = angular.module('MyModule', [], function ($routeProvider) { >> $routeProvider >> .when('/home', {templateUrl: 'home.php'}) >> .when('/page/*:someParam*', {templateUrl: 'page.php',}). >> .otherwise({redirectTo:'/home'}); >> }); >> >> *However, I know decide that I need to actually pass the value of >> :someParam to the server to do "some work"; basically I want the following >> request to goto my server: page.php?param=<value of :someParam> How would >> I accomplish this?* >> >> Things I have tried: >> - referencing :someParam in the templateUrl results in the following >> query string: page.php?param=:someParam >> - injecting $routeParamsProvider into the configuration block (along with >> $routeProvider). This did not seem to add valuable information, since the >> route is configured once and this shoudl be dynamic behavior. >> - modified the configuration to look like the following. This >> successfully resulted in the location showing the correct URL, but did not >> dispatch this URL to the server. >> >> .when('page/:someParam', { >> templateUrl: 'page.php', >> redirectTo: function(pathParams, path, search) { >> return >> 'page/'+pathParams[someParam]+'/?param='+pathParams[someParam]; >> } >> } >> >> I am well aware that I could limit the users interaction with the link >> that causes this route change to trigger (through ng-show, or just plain >> php). I am also aware that I could limit functionality on 'page.php' >> itself in a controller. Neither of these solutions fit my requirements. >> >> Thank you for any help you can offer! >> > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
