Fix bug on search result ui

Fix issue #3852, After global search result returned if you research another item, the content will not refresh.
This commit is contained in:
Deng, Qian 2018-04-23 19:58:22 +08:00
parent 5089b26cf8
commit 456b0c40cb

View File

@ -11,8 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { Router, NavigationExtras } from '@angular/router';
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy, ChangeDetectorRef, OnInit } from '@angular/core';
import { Router, NavigationExtras, NavigationEnd } from '@angular/router';
import { Repository } from 'harbor-ui';
import { State } from 'clarity-angular';
@ -23,7 +23,7 @@ import { SearchTriggerService } from '../../base/global-search/search-trigger.se
templateUrl: 'list-repository-ro.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ListRepositoryROComponent {
export class ListRepositoryROComponent implements OnInit {
@Input() projectId: number;
@Input() repositories: Repository[];
@ -34,8 +34,22 @@ export class ListRepositoryROComponent {
private router: Router,
private searchTrigger: SearchTriggerService,
private ref: ChangeDetectorRef) {
let hnd = setInterval(()=>ref.markForCheck(), 100);
setTimeout(()=>clearInterval(hnd), 1000);
this.router.routeReuseStrategy.shouldReuseRoute = function(){
return false;
};
this.router.events.subscribe((evt) => {
if (evt instanceof NavigationEnd) {
// trick the Router into believing it's last link wasn't previously loaded
this.router.navigated = false;
// if you need to scroll back to top, here is the right place
window.scrollTo(0, 0);
}
});
}
ngOnInit(): void {
let hnd = setInterval(() => this.ref.markForCheck(), 100);
setTimeout(() => clearInterval(hnd), 1000);
}
refresh(state: State) {