简体   繁体   English

Nativescript Angular参数未从一个组件传递到另一个组件

[英]Nativescript Angular parameter not getting passed from one component to another

In a TabView template app am trying to pass an id claimid from one component to another when routing. 在TabView模板应用中,正在尝试在路由时将ID索赔ID从一个组件传递到另一个组件。 I am arriving at the desired compionent/template but the claimid I am passing is undefined 我正在到达所需的组分/模板,但我传递的Claimid 不确定

In my app-routing.module.ts I have 在我的app-routing.module.ts中

...
{ path: "reports", component: ReportsComponent, outlet: "reportsTab" },
    { path: "report/:reportid", component: ReportComponent, outlet: "reportsTab" },    
    { path: "expense/:clainid", component: ReceiptComponent, outlet: "reportsTab" },    

.... ]; ....];

I am navigating by this: 我正在导航:

    public OnTapReceipt(claimid) {
    console.log("OnTapReceipt tapped "+claimid);
    this.router.navigate([{
        outlets: {
            reportsTab: ['expense', claimid] 
        }
      }]);
}

In the destination receipt.component.ts I have 在目标收据.component.ts中

import { Router, ActivatedRoute } from "@angular/router";

...

constructor(private router: Router, 
    private expenseService: ExpenseService, 
    private page: Page, 
    private routerExtensions: RouterExtensions, 
    private route: ActivatedRoute) {

}

...

ngOnInit() {
    this.claimid = this.route.snapshot.params["claimid"];
    console.log("Claimid in receipt compt ngOnInit: "+this.claimid);
    this.showReceipt();
}
showReceipt() {
    this.claimid = this.route.snapshot.params["claimid"];

    console.log("Claimid in receipt compt: "+this.claimid);
    //alert("ouch!");
    this.expenseService.getReceipt(this.claimid)
    .subscribe(
        (data) => {
            let output=JSON.stringify(data);
            console.log("receipt in receipt component = "+output.substr(0, 100));
            if (data["reports"]=="No Expenses") {                 
                // No reports to show
            } else {  
                let receipt_filetype=data.file_type;
                let receipt_data=data.img_data;
            }
        },
        (error) => {
            alert("Unfortunately we could not get the receipt.");
        }
    );      
}

And the console shows 控制台显示

JS: OnTapReceipt tapped 26435
JS: Claimid in receipt compt ngOnInit: undefined
JS: Claimid in receipt compt: undefined

Any idea how and why my claimid is being dropped? 知道如何以及为什么要删除我的索赔编号吗? Thanks. 谢谢。

Try 尝试

{ path: "reports", component: ReportsComponent, outlet: "reportsTab" },
{ path: "report/:reportid", component: ReportComponent, outlet: "reportsTab" },    
{ path: "expense/:claimid", component: ReceiptComponent, outlet: "reportsTab" 
},    

clainid != claimid clainid!=索赔编号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 阻止一个组件从另一个组件angular6获取CSS - Block one component getting CSS from another component angular6 没有收到从一个组件传递到另一个组件的 angular 路由器参数值? - Not receiving a angular router param value passed from one component to another component? 传递 boolean 值不会从一个组件共享到另一个组件 - Angular - Passing boolean value is not getting shared from one component to another - Angular 角度-将一个组件作为参数传递给另一个 - Angular - Passing one component as parameter to another 从 Angular 7 中的 API 获得响应后,如何将一个组件的值传递给另一个组件 - How to pass value one component to another component after getting response from an API in Angular 7 Angular:从另一个组件传递的数据在页面重新加载时变得未定义 - Angular: data passed from another component becomes undefined on the page reload 从 Angular 10 中的另一个组件获取价值 - Getting value from another component in Angular 10 兄弟组件未从子组件获取更新的参数值 - Angular - Sibling component is not getting updated parameter value from child component - Angular 从一个组件传递的数据在另一个组件中显示未定义 - passed data from a component shows undefined in another one Angular 2.调用组件和获取参数只工作一次 - Angular 2. Calling a component and getting the parameter works one time only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM