0
我有这段代码应该显示h4,如果搜索查询不匹配任何字符串,就说没有产品。我现在有这个奇怪的错误,我的文字没有显示。它可以在html和css(控制台)中使用,并在单击包含click()的元素或在css(控制台)中编辑颜色后运行。有谁知道这可能是什么,我怎么能解决这个问题,已经尝试吨的东西,但似乎没有帮助?在Angular JS中没有显示文字
我加入像这样 - >
<h4 ng-show="filteredItems.length == 0" class="explanation">We found no products</h4>
CSS
h4 {
color: #ccc;
text-align: center;
padding: 100px 20px;
}
搜索
$scope.searchItem = function(query) {
foundItems = [];
query.toLowerCase();
if(searchTimeout)
$timeout.cancel(searchTimeout);
searchTimeout = $timeout(function() {
for(var i = 0; i < $scope.items.length; i++) {
if($scope.items[i].name.toLowerCase().indexOf(query) > -1)
foundItems.push($scope.items[i]);
}
$scope.filteredItems = foundItems;
}, 400);
}
编辑
// fill with dummy data
$scope.define = function() {
var random;
for(var i = 0; i < 114; i++) {
random = Math.floor(Math.random() * 6) + 1;
var text;
switch(random) {
case 1:
text = 'Double espresso';
break;
case 2:
text = 'Frappuccino cookie crumble chocolate'
break;
case 3:
text = 'Cappuccino'
break;
case 4:
text = 'Very Berry Hibiscus Starbucks Refreshers™ Beverage'
break;
case 5:
text = 'Clover® Brewed Coffee Coffee Traveler'
break;
case 6:
text = 'Featured Dark Roast'
break;
default:
text = 'Not defined'
}
$scope.data.items.push({ name: text, image: random });
}
// THIS LINE CAUSES THE PROBLEM (uncommented everything works)
//$scope.data.filteredItems = $scope.data.items;
}
$scope.define();
非常感谢!我要检查一下。伟大的提示。 ty再次;) – 2014-09-25 20:00:15
我试图打破它,但我一直没能成功地做到这一点...:s – 2014-09-26 12:24:51
嘿@owen我想我已经解决了我的问题,但我不知道它为什么会影响我码。你知道吗?我已经在 – 2014-09-30 10:45:47