[英]How to set the AngularJS $routeProvider's routes by json
我想在通過JSON對象獲取pathconfig之后設置路徑,該怎么辦? 因此,網絡服務器提供了一個json對象,該對象包含路徑,模板,控制器,在將角度設置為$ routeProvider之后,它對我是有好處的,在設置routeProvider后可以對其進行修改,以便它得到json響應會將其包含的內容添加到routeProvider。
后面跟一個冒號':'
例如,假設您的json看起來像這樣:
"objects": [
{ "itemID": "121", "itemName": "Doe" },
{ "itemID": "122", "itemName": "Smith" },
{ "itemID": "123", "itemName": "Jones" }
]
在您的.js文件中:
$routeProvider.when('/item=:itemID', { //FOLLOW BY A COLON RIGHT HERE
templateUrl: 'itemOverview.html', //change as you like
controller: 'itemOverviewController' //change as you like
});
取決於您如何獲取json以及為$ scope命名的名稱,ng-repeat中的名稱應由您決定。
在HTML中,鏈接應如下所示:
<ul class="itemList">
<li ng-repeat="object in objects">
<!-- a '#' is required at the beginning of 'href=' for routeProvider -->
<a href="#/item={{object.itemID}}">{{object.ItemName}}</a>
</li>
</ul>
使用ng-repeat,angular會處理列表及其附帶的鏈接!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.