My route example:
angular.module('test', [], function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'pageOne.html',
controller: ControllerOne
}).when('/?:foo, { templateUrl: '
pageTwo.html ', controller: ControllerTwo });`
But if I load page like http://example.com/?someFoo my route doesn't load ControllerTwo, it load ControllerOne. What I doing wrong? Thanks.
I think the format is not correct.
angular.module('test', [], function ($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'pageOne.html',
controller: 'ControllerOne'
}).when('/foo/:foo', { templateUrl: '
pageTwo.html ', controller: 'ControllerTwo' });
and load page like http://example.com/#/foo/someFoo
I would suggest you to have
.otherwise({ redirectTo: '/nosuchpage.html'})
Then you will know if your link is wrong.
You need to pass controller names as strings
This works
var myApp = angular.module('myApp',[],function($routeProvider) {
$routeProvider
.when('/home',{templateUrl:'home.html'})
.when('/page1',{templateUrl:'page1.html', controller:'ctrl1'})
.when('/page2',{templateUrl:'page2.html', controller:'ctrl2'})
.otherwise({redirectTo:'/home'});
});
function ctrl1($scope){
$scope.something = 'Hello from page 1';
}
function ctrl2($scope){
$scope.something = 'Hello from page 2';
}
jsfiddle: http://jsfiddle.net/jaimem/T2TWB/1/
It doesn't seem to be supported by Angular. Check out https://groups.google.com/d/topic/angular/5l4bbnWp18M/discussion