2014-06-24 17 views
0

開始我有這樣的代碼:AngularJS - 改變templateUrl如果routeprovider某些文本

var app = angular.module('TabsApplication', ['ngRoute']) 
    .config(['$routeProvider', function($routeProvider) { 
     $routeProvider 
     .when('/search', { 
      templateUrl: 'search.html', 
      controller: 'SearchController' 
     }) 
     .otherwise({ 
      redirectTo: '/home' 
     }); 
    }]) 

現在,我去http://myapp.com/#/search,它會顯示search.html。我想要的是,如果我去http://myapp.com/#/search?search1=1&search2=2,它也會顯示search.html。

如果我使用'/search*',如果輸入http://myapp.com/#/search,它將重定向到首頁,但如果輸入http://myapp.com/#/search *,它將顯示search.html。

有沒有辦法做到這一點?我正在使用AngularJs版本1.2.9。

+0

查詢參數應該只需使用'/ search' –

回答

0

enter code here變種應用= angular.module( 'TabsApplication',[ 'ngRoute']) 的.config([ '$ routeProvider',函數($ routeProvider){$ routeProvider

 .when("/search", { 
     templateUrl: 'html/somepath/search.html' 
     controller: 'SearchController' 
    }) 
    .otherwise({ 
     redirectTo: '/home' 
    }); 
}])`enter code here` 
+1

我建議你使用絕對路徑代替templateUrl的相對路徑, – user3773047