在Angular中顺序运行组件

时间:2019-06-19 08:42:52

标签: javascript angular typescript

i具有用于angular的分页的分量。

它有Input

  @Input('TPage') TPage: number;

我将这样的输入传递到基本组件中:

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

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

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

如何解决此问题????

BaseComponent:

  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)
      }
    }
  }

0 个答案:

没有答案