javascript - 在 Angular 中按顺序运行组件
问题描述
我有一个分页组件 angular 。
它有Input
:
@Input('TPage') TPage: number;
我在基本组件中传递这个输入,如下所示:
<app-paging [TPage]="totalPage"></app-paging>
我需要填写totalPage
然后将其发送到组件,但首先发送totalPage
到app-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)
}
}
}
解决方案
推荐阅读
- r - “agg(x, ...) 中的错误:agg 只能支持列或字符”错误
- objective-c - 宏块上的 Objective-C clang-format 并对齐 args
- debugging - 如何修复代码块调试器的“未知选项‘nx’”
- async-await - 将 next.js 配置为使用 Babel 不转换异步函数
- jquery - Select2 - 使用事件 mouseenter 获取值
- python - 如何按希尔伯特曲线的顺序将二维矩阵(nxn)展平为一维数组?
- c# - Windows 窗体应用程序的设置项目部署:图像路径错误 (itextsharp)
- flutter - 什么是颤振中的 android.media.AudioTrack 等价物?
- sql-server - 如何仅使用存储过程将 Excel 数据导入 My Sql Server 表
- node.js - 带有状态的 Webpack React 下载页面