我尝试将可折叠的手风琴风格添加到我的项目中。标题似乎使其成为UI,但它不会展开以显示可折叠主体部分。谁知道我怎么能做这个工作?或者看看它为什么不是?
这是我的HTML:
<div class="section">
<div ng-repeat="diary in diaries | orderBy:'date' ">
<div class="row">
<div class="col s2 push-s11">
<a class="btn-floating btn-large waves-effect waves-light red right-align" ng-click="deleteDiary(diary.id)"><i class="material-icons">delete_forever</i></a>
</div>
</div>
<div class="row">
<h5 class="center-align"><b>{{diary.category}}</b></h5>
<h6 class="center-align">{{diary.date}}</h6>
</div>
<div class="row">
<div class="foodContainer">
</div>
<div class="row center-align">
<ul class="collapsible popout" data-collapsible="accordion" watch>
<li ng-repeat="food in diary.foods">
<div class="collapsible-header">{{food.title}}</div>
<div class="collapsible-body">
<label><b>Calories: </b><p>{{food.calories}}</p></label>
<label><b>Fat: </b><p>{{food.fat}}</p></label>
<label><b>Protein: </b><p>{{food.protein}}</p></label>
<label><b>Sodium: </b><p>{{food.sodium}}</p></label>
<label><b>Sugars: </b><p>{{food.sugars}}</p></label>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
这是我初始化可折叠的控制器:
"use strict";
app.controller("DiaryCtrl", function($scope, $rootScope, $location, DiaryFactory, FoodFactory){
$scope.selectedDiary = '';
// $scope.selectedDiary = 'Diary0';
$scope.totalCalories = 0;
$scope.totalFat = 0;
$scope.totalProtein = 0;
$scope.totalSodium = 0;
$scope.totalSugars = 0;
$scope.diaries = [];
$scope.foods = [];
//activate materialize collapsible list
$('.collapsible').collapsible();
//getMeals
//lists all meals on the diary page
let getAllDiaries = function(){
DiaryFactory.getDiary($rootScope.user.uid).then(function(FbDiaries) {
$scope.diaries = FbDiaries;
console.log('diaries: ', $scope.diaries);
FoodFactory.getFoodsFB($rootScope.user.uid).then(function(FbFoods){
console.log('foods from controller', FbFoods);
FbFoods.forEach(function(food){
$scope.diaries.forEach(function(diary){
// console.log('foods', food);
if(food.mealId === diary.id){
diary.foods = diary.foods || [];
diary.foods.push(food);
console.log('foods array on diary', diary.foods);
}
});
});
});
});
};
getAllDiaries();
以下是截图: Screen Shot
答案 0 :(得分:4)
我之前遇到过与React.js和Materialize CSS相同的问题。
原因与@DennyHio完全相同,那些DOM不可折叠,因为它们是在Materialise CSS完成初始化程序后由Angular / React创建的。
我们必须手动&#34;初始化&#34;那些DOM:
function afterAngularOrReactHasCreatedAllDOM (){
// Manually make all DOM with .collapsible collapsible
$('.collapsible').collapsible();
}