首页 > 解决方案 > 在 Angular 中按顺序运行组件

问题描述

我有一个分页组件 angular 。

它有Input

  @Input('TPage') TPage: number;

我在基本组件中传递这个输入,如下所示:

  <app-paging [TPage]="totalPage"></app-paging>

我需要填写totalPage然后将其发送到组件,但首先发送totalPageapp-paging然后填写totalPage.

现在我需要先填充totalPage然后运行app-paging​​.

我怎么解决这个问题 ????

基础组件:

  id: number;
  newModesList: PageListMetadata<Newsmodel[]>;
  catid: Deletemodel;
  totalPage: number;
  totalPagesList: number[] = [];
  constructor(private route: ActivatedRoute, private newsService: NewsmanagerService) {
    this.route.params.subscribe(data => {
      this.catid = newsService.IntialDeletemodel();
      this.id = +this.route.snapshot.paramMap.get('id');
      this.FetchData()
      this.catid.id = this.id;

    })
  }

  ngOnInit() {

  }

  FetchData(pagenumber: number = 1) {
    this.newsService.GetCategoryListNews(this.id, pagenumber).subscribe(data => {
      this.newModesList = data.data,
      this.totalPage=data.data.totalPages,
      console.log('in base',this.newModesList.totalPages)
    })
  }

  SendRequestforPaging(item: number) {
    this.FetchData(item)
  }

这是app-paging

    @Input('TPage') TPage: number;
  totalPagesList: number[]=[];

  constructor() {
    console.log('in page',this.TPage)
    this.PushTotalPageInArray(this.TPage);
  }

  ngOnInit() {
  }

  PushTotalPageInArray(item: number) {
    if (this.totalPagesList.length <= 0) {
      for (let i = 0; i < item; i++) {
        this.totalPagesList.push(i)
      }
    }
  }

标签: javascriptangulartypescript

解决方案


推荐阅读