Angular 2 when passing id in url it's showing ?complntId=TS0000031

ε祈祈猫儿з 提交于 2019-12-01 22:27:25

问题


have a scenario,if user enters one number and submit it should navigate to that id and display the details.

when i navigate url,it's showing something like this

complaintstatus/TS0000031?complntId=TS0000031

Detail view code:

export class ComplaintDetailComponent implements OnInit {
    id:number;
    private sub:any;
    complntId : any;
    constructor(private ComponentService:ComplaintService,private route:ActivatedRoute){

    }
    ngOnInit() {

   this.sub= this.route.params.subscribe((params:Params)=>{
        this.ComponentService.getCompliants(params['complntId'])
    });
    console.log(this.sub);

  }

user enters id code :

export class ComplaintStatusComponent {

    constructor(private router:Router){}
getComplaintDetails(complntId){
  this.router.navigate(['/complaintstatus', complntId]);
}  

}

and one more question,how can i send user enter id to another component.

and service code:

export class ComplaintService{
    private _url:string ="http://192.168.0.106:8000/app/complaint/complaintstatus"
    constructor(private _http:Http){}
    getCompliants(complntId){
        return this._http.get(this._url + '/' + complntId).map((response:Response)=>response.json());

    }
}

routing Module:

const routes: Routes = [
    {path:'complaintregistration',component:ComplaintRegistartionComponent},
    {path:'complaintstatus',component:ComplaintStatusComponent},
    {path:'complaintstatus/:complntId',component:ComplaintDetailComponent}
];

来源:https://stackoverflow.com/questions/44096308/angular-2-when-passing-id-in-url-its-showing-complntid-ts0000031

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!