-2
我想根據用戶的操作引用1個索引(將有30個不同的索引),然後使用ng-repeat來遍歷索引中的每個項目。動態引用數組
控制器:
$scope.meals = [
{ title: 'Abs', url:"#/app/mworkouts",id: 100, img: "img/female.jpg", vid:"https://media.giphy.com/media/TLpGHso4sEJlS/giphy.gif",},
{ title: 'Arms', url:"#/app/browse",id: 2 , img: "img/male.jpg", vid:"https://media.giphy.com/media/ZYi2Lc03nrryw/giphy.gif"},
{ title: 'Biceps', url:"#/app/search",id: 3, img: "img/Spotify_2.jpg", vid:"https://media.giphy.com/media/zOleW7sjYngQ0/giphy.gif" },
{ title: 'Legs', url:"#/app/search",id: 4, img: "img/Spotify_4.jpg", vid:"https://media.giphy.com/media/srNYANrTyYeFW/giphy.gif" },
{ title: 'Core', url:"#/app/mworkouts",id: 5, img: "img/female.jpg", vid:"https://media.giphy.com/media/4YAkSYGsKieXK/giphy.gif" },
{ title: 'Back', url:"#/app/mworkouts",id: 6, img: "img/male.jpg", vid:"https://media.giphy.com/media/8eBAeU1W4kV68/giphy.gif" }
];
$scope.deserts = [
{ title: 'Chocolate', url:"#/app/mworkouts",id: 1 },
{ title: 'Cake', url:"#/app/browse",id: 2 },
{ title: 'Ice Cream', url:"#/app/search",id: 3 },
{ title: 'Sundae', url:"#/app/search",id: 4 },
{ title: 'Cherry Pie', url:"#/app/mworkouts",id: 5 },
{ title: 'Apple Pie', url:"#/app/mworkouts",id: 6 },
{ title: 'Pumpkin Pie', url:"#/app.mworkouts", id: 7}
];
$scope.allbooks = [{
'book1': {
title: "Eat Pray Don't Love",
price: 3.99,
workoutname: "meals"
},
'book2': {
title: "Hello Fadder Hello Mudder",
price: 19.99,
workoutname:"deserts"
}
}, {
'book2': {
title: "DaVinci Code",
price: 7.99,
workoutname:"deserts"
}
}];
功能設置選擇:
$scope.pick = function(selectedBook) {
$rootScope.choice = selectedBook;
}
終於HTML:
<div ng-repeat="m in {{choice.workoutname}}">
<div ng-if="meal_index==$index" ng-init="startCount=m.id">
<img src="{{m.img}}" style="width:100%; height:100%;max-width:500px;">
<img src="{{m.vid}}" style="width:100%; height:100%;max-width:500px;">
<p>
{{m.title}} {{m.id-40}}<!-- {{$index+1}} --> out of {{meals.length}} {{startCount}}
<button ng-click='vs(m.id)'>Setter</button>
</div>
</div>
對不起所有的怪異的名字......這只是一個例子。在此先感謝:)
除非你有一個真正需要使用$ rootScope存儲選擇,堅持使用$範圍。也看不到接線功能。 – Will
究竟是什麼問題?什麼不行?報告了哪些錯誤?怎麼了? – Pointy
視圖中沒有與設置的範圍變量或方法相關的值。奇怪的名字沒有問題,但至少必須得到全面的代碼。 – swestner