2016-03-02 69 views
1

我試圖讓狀態根據參數提供5個狀態。帶參數的離子狀態

這裏是app.js:

.config(function($stateProvider, $urlRouterProvider) { 
$urlRouterProvider.otherwise('/'); 
$stateProvider 

.state('home' , { 
    url:'/', 
    templateUrl: 'home.html' 
}) 
.state('car' , { 
    url:'/car/:carId', 
    templateUrl: 'car{{carId}}.html', 
    controller: function($scope, $stateParams) { 
     $scope.carId = $stateParams.carId; 
    } 
    }); 
}) 

ID爲作品中的url,但我該怎麼做模板的URL爲html頁面一樣,現在我的列表項的狀態都顯示5相同的內容。

<a class="item" ui-sref="car({ carId: 1})"> 
    Car 1 
</a> 

的問題是在腳本定義爲templateUrl的。ID:

有5個項目在這裏我呼籲國家例如列表

<script type="text/ng-template" id="car{{carId}}.html"> 
    <ion-view view-title="Car 1"> 
    <ion-content> 
     <h1>car1</h1> 
    </ion-content> 
    </ion-view> 
</script> 

是否有可能傳遞carId腳本定義id和app.js templateUrl那麼每個頁面都會有不同的內容?

回答

1

你作爲ui-router wiki描述的功能來定義您的templateUrl:

$stateProvider.state('contacts', { 
    templateUrl: function ($stateParams){ 
    return '/car' + $stateParams.carId + '.html'; 
    } 
})