如果找不到与用户输入匹配的内容,我想显示一条消息。我使用angular-filter。
在此示例中设置了变量filteredPages,我可以获取当前长度并正确显示消息。
<div ng-repeat="page in filteredPages = (pages | filterBy: ['name', 'about', 'location.street', 'location.city', 'location.zip']: search) | orderBy: '-likes'" ng-click="openPage(page)"></div>
{{filteredPages.length}}
<div ng-if="!filteredPages.length">Não foi encontrado nenhuma página com "{{search}}".</div>
在这个类似的例子中,由于某种原因,变量filteredEvents始终为null。因此,如果找不到匹配项,我就无法正确显示消息。
<div ng-repeat="date in events | orderBy:'date'" ng-if="(date.events | filterBy: ['name', 'start_time', 'end_time', 'place.name', 'place.location.street', 'place.location.city', 'place.location.zip']: search).length">
<div ng-repeat="event in filteredEvents = (date.events | filterBy: ['name', 'start_time', 'end_time', 'place.name', 'place.location.street', 'place.location.city', 'place.location.zip']: search) | orderBy:'-attending_count'" ng-click="openEvent(event)"></div>
</div>
{{filteredEvents.length}}
<div ng-if="!filteredEvents.length">Não foi encontrado nenhum evento com "{{search}}".</div>
知道我做错了什么吗?