我目前正在为某人构建一个 Ionic 应用程序,但我在使用 ng-hide 和 ng-scroll 时遇到了一些问题。该页面显示产品,您可以在查看营养素或成分之间切换。我使用 ng-hide & ng-show 来实现这一点。但是,当我按下按钮切换数据时,滚动条就乱了。我附上了一个简短的视频来演示这个问题:https : //youtu.be/W9fFMdSLW8s
以下是一些可能有助于深入了解的代码片段。
编辑:我制作了一个重现问题的代码笔:
http://codepen.io/JeremyKeusters/pen/qmBwzp
重现步骤:
模板页面:
<table class="ingredients" ng-show="toggle">
<tr>
<th class="left">Ingredient</th>
<th class="right">Amount per<br>100 ml</th>
</tr>
<tr ng-repeat="ingredient in JuiceIngredients">
<td class="left">{{ingredient.Ingredient.Name}}</td>
<td class="right">{{ingredient.Ingredient.Amount_g}} g</td>
</tr>
</table>
<table class="nutrients" ng-hide="toggle">
<tr>
<th class="left">Nutrient</th>
<th class="right">Amount per 100 ml</th>
<th class="right">% of reference quantity</th>
</tr>
<tr ng-repeat="nutrient in JuiceNutrients">
<td class="left">{{nutrient.Nutrient.Name}}</td>
<td class="right" ng-bind-html="nutrient.Nutrient.Amount_html"></td>
<td class="right">{{(nutrient.Nutrient.PartOfRI * 100 | number:0)}} %</td>
</tr>
</table>
<br>
<button ng-click="toggle=!toggle;" class="button button-block button-balanced default-button">
<span ng-hide="toggle">Show ingredients</span>
<span ng-show="toggle">Show nutrients</span>
</button>
控制器.js:
bottleSrv.getBottleDetails($rootScope.scannedCode).then(function (data) {
$scope.JuiceID = data.JuiceID;
$scope.ExpirationDate = data.ExpirationDate;
$scope.JuiceImg = "https://someurl.com/task.php?token=" + $rootScope.userToken + "&juice_id=" + data.JuiceID + "";
juiceSrv.getJuiceDetails($scope.JuiceID).then(function (data) {
$scope.JuiceName = data.Name;
$scope.JuiceDescription = data.Description;
})
juiceSrv.getJuiceIngredients($scope.JuiceID).then(function (data) {
$scope.JuiceIngredients = data;
})
juiceSrv.getJuiceNutrients($scope.JuiceID).then(function (data) {
$scope.JuiceNutrients = data;
})
});
有人有解决这个问题的方法吗?提前感谢您的帮助!
-杰里米
我终于找到了这个问题的答案。我在 ion-content 元素中添加了 overflow-scroll 元素。
<ion-content overflow-scroll="true">
这解决了问题。它确实与底部间距有些混乱,但您可以使用一些 CSS 修复它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句