Angular 我的页码打错了。。。。但是我的页面工作正常
我现在正在学习。我确实用这种语言在商业上创建了应用程序。我做错了什么,因为我的页码不好。 不幸的是,我不知道我在哪里犯了错误。我应该在代码中改进什么?请帮忙 我的代码:Angular 我的页码打错了。。。。但是我的页面工作正常,angular,pagination,Angular,Pagination,我现在正在学习。我确实用这种语言在商业上创建了应用程序。我做错了什么,因为我的页码不好。 不幸的是,我不知道我在哪里犯了错误。我应该在代码中改进什么?请帮忙 我的代码: import { Component, OnInit } from '@angular/core'; import { CompanyService } from './../services/company.service'; import { NgbPaginationConfig } from '@ng-bootstra
import { Component, OnInit } from '@angular/core';
import { CompanyService } from './../services/company.service';
import { NgbPaginationConfig } from '@ng-bootstrap/ng-bootstrap';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { IPage } from './../services/page';
import { Observable } from 'rxjs';
import { Router } from '@angular/router';
import { RouterModule, Routes } from '@angular/router';
import { ActivatedRoute } from "@angular/router";
@Component({
selector: 'app-company-profile',
templateUrl: './company-profile.component.html',
styleUrls: ['./company-profile.component.css']
})
export class CompanyProfileComponent implements OnInit {
public company = [];
public errorMsg;
page;
numberOfPage;
numberOfPageTMP;
pageSize;
private _url;
constructor(private _companyService: CompanyService, config: NgbPaginationConfig, private http: HttpClient, private router: Router, private route: ActivatedRoute) {
this.page = Number(this.route.snapshot.paramMap.get("page"))
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
}
ngOnInit() {
this.page = Number(this.route.snapshot.paramMap.get("page"))
this.getCompany2(this.page)
.subscribe(data => {
this.company = [data]
this.numberOfPage = this.company[0].numberOfPage;
this.pageSize = this.company[0].pageSize;
},
error => this.errorMsg = error);
}
pageChange(page) {
this.router.navigate(['companies/' + page]);
}
url2(page) {
//api/company?page=1&language=pl"
return "http://localhost:4200/api/company?page=" + page + "&language=pl";
}
getCompany2(page): Observable<IPage> {
return this.http.get<IPage>(this.url2(page));
}
errorHandler(error: HttpErrorResponse) {
return Observable.throw(error.message || "Server Error");
}
}
从'@angular/core'导入{Component,OnInit};
从“/../services/company.service”导入{CompanyService};
从'@ng bootstrap/ng bootstrap'导入{NgbPaginationConfig};
从“@angular/common/http”导入{HttpClient,HttpErrorResponse};
从“/../services/page”导入{IPage};
从“rxjs”导入{Observable};
从'@angular/Router'导入{Router};
从'@angular/router'导入{RouterModule,Routes};
从“@angular/router”导入{ActivatedRoute}”;
@组成部分({
选择器:“应用程序公司配置文件”,
templateUrl:“./company profile.component.html”,
样式URL:['./公司简介.component.css']
})
导出类CompanyProfileComponent实现OnInit{
上市公司=[];
公共错误消息;
页
页码;
页码TMP;
页面大小;
私有url;
构造函数(private _companyService:companyService,config:NgbPaginationConfig,private http:HttpClient,private router:router,private route:ActivatedRoute){
this.page=编号(this.route.snapshot.paramMap.get(“page”))
this.router.RouterUseStrategy.shouldReuseRoute=()=>false;
}
恩戈尼尼特(){
this.page=编号(this.route.snapshot.paramMap.get(“page”))
this.getCompany2(this.page)
.订阅(数据=>{
this.company=[数据]
this.numberOfPage=this.company[0].numberOfPage;
this.pageSize=this.company[0].pageSize;
},
error=>this.errorMsg=error);
}
页面更改(第页){
这个.router.navigate(['companys/'+page]);
}
url2(第页){
//api/公司?页面=1,语言=pl“
返回“http://localhost:4200/api/company?page=“+page+”&language=pl”;
}
getCompany2(第页):可观察{
返回this.http.get(this.url2(page));
}
errorHandler(错误:HttpErrorResponse){
返回可观察的.throw(error.message | |“服务器错误”);
}
}
和html代码:
<ngb-pagination [collectionSize]="numberOfPage*10" [(page)]="page" [maxSize]="5" [rotate]="true" [boundaryLinks]="true" (pageChange)="pageChange(page)"></ngb-pagination>
<pre>Current page: {{page}}</pre>
dsdsddsds: {{collectionSize}}
dsdsddsds: {{company[0].numberOfPage}}
sru: {{numberOfPage}}
当前页:{{page}
DSDDDS:{{collectionSize}
DSDDDS:{{公司[0].numberOfPage}
sru:{{numberOfPage}}
您有一个类型错误。必须使用(pageChange)=“pageChange($event)”
-您已经编写了pageChange(page)-
回复结束。但我建议您订阅paramMap,因此,如果导航器中的url发生了一些更改,您的应用程序将正常工作,请参阅本文中的示例
有些人喜欢
您有一个类型错误。必须使用
(pageChange)=“pageChange($event)”
-您已编写了pageChange(page)-
回复结束。但我建议您订阅paramMap,因此,如果导航器中的url发生了一些更改,您的应用程序将正常工作,请参阅本文中的示例
有些人喜欢
this.activateRouter.paramMap.pipe(
//well we don't want the page
switchMap((params: ParamMap)=>{
this.page=+params.get('page');
//we return the call of the service
return this.dataService.getData(this.page)
})).subscribe(data=>{
this.company = [data]
this.numberOfPage = this.company[0].numberOfPage;
this.pageSize = this.company[0].pageSize;
})