Is there a way to refresh virtual repeat container?

你说的曾经没有我的故事 提交于 2019-12-05 13:47:06
Peter Drinnan

You can force a redraw of your md-virtual-repeat container by triggering a fake window resize event (this causes the directive to call its private handleScroll_() method which then calls containerUpdated()).

This will trigger a fake window resize event:

angular.element(window).triggerHandler('resize');

You can also use this to cause refresh of items in specific scope and not in the entire document:

scope.$broadcast('$md-resize')
Paul Gambke

Resetting the model should also work.

In your case you could a have a new function on infiniteItems:

refresh : function() {
            this.numLoaded_= 0;
            this.toLoad_ = 0;
            this.items = [];
          }

I'm going to post my solution since there isn't an answer yet. If an better answer gets posted I'll gladly accept it.

First, I migrated all of my search result code into it's own template, directive and controller.

Next, I added an empty container in place of my logic. I'll use this as a place to dump my directive dynamically every time I search.

`<div id="search-result-container"></div>`

Finally, I dynamically appended my new directive like this

$scope.handleHotlineSearchClick = function () {           
    var query = $('#legal-search-input').val();

    if (query != "") {
        $scope.searchLoaded = false;
        $('#search-result-container').empty().append($compile("<search-result></search-result>")($scope));
    }
};

This way every time the user enters a new search term the directive gets reloaded.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!