2013-10-02 42 views
0

我有一個單獨的頁面web應用程序,其中的任何請求以請求開始,例如, http://localhost/appname/request*,使用IIS URL重寫模塊將主頁發送回客戶端。帶有angularJS的IIS URL重寫模塊不起作用

當Angular收到網頁時,它會看到路線。我需要確保Angular拾取routeParams。

客戶端請求: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('!'); 

控制器監聽$routeChangeSuccess

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

此外,網址更改爲主頁。即我被重定向到http://localhost/appname

我做錯了什麼?

回答

1

如果我理解正確的話,你想要得到的路線PARAMS但要做到這一點,正確的做法是通過注入$ routeParams到控制器:

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

}); 

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

+0

HTTP://docs.angularjs .org/tutorial/step_07 –

+0

如果您嘗試使用html 5模式,請查看:http://stackoverflow.com/questions/16677528/location-switching-between-html5-and-hashbang-mode-link-rewriting –

+0

謝謝。我被重定向的原因是因爲'否則'規則。我沒有真正做出任何改變,但現在正在工作。此外,我不必傳遞'$ routeParams'以及'$ scope'。我使用'$ scope。$ on('$ routeChangeSuccess',function(event,routeData){});'在我的'Myctrl'裏面。 – lostpacket