首页 > 解决方案 > 如何将值从角度方法传递给属性

问题描述

您好我正在尝试将值从方法传递给属性

这是我的代码

我想将 sub_id_1 传递给 subscription_id 下的选项

我正在尝试 3 天任何帮助,请

这是一个剃须刀集成我正在从 python 获取响应并以角度恢复它,但我认为我被锁定在 buy() 方法

public buy() {
    return this.http.get("http://127.0.0.1:5000/razor_sub",{
    }).subscribe(
    (res)=>{
      var rrre = res.json();
      var sub_id_1 = rrre.id;  
      if (sub_id_1) {
        console.log(sub_id_1);
        const type = sub_id_1;
        this.sub_response_id(sub_id_1)
      }
     
    });
    
   }
   /**
    *  sub_response_id
    */
   public  sub_response_id(sub_id_1) {
    this.initPay(sub_id_1)
   }
   
   public options: any = {
    
    key: 'rzp_test_******',
    subscription_id: this.sub_response_id(sub_id_1),
    name: "Acme Corp.",
    description: "Monthly Test Plan",
    image: "#",
    handler: function(response) {
      //alert(response.razorpay_payment_id),
      //alert(response.razorpay_subscription_id),
      //alert(response.razorpay_signature);
    },
    prefill: {
      name: "Tamer Jarrar",
      email: "tamerjrrar@example.com",
      contact: "+919876543210"
    },
    notes: {
      note_key_1: "Tea. Earl Grey. Hot",
      note_key_2: "Make it so."
    },
    theme: {
      color: "#F37254"
    }
  };
  initPay(sub_id_1): void {
    this.rzp = new this.winRef.nativeWindow['Razorpay'](this.options);
    this.rzp.open();
  }

  paymentHandler(res: any) {
    this.zone.run(() => {
    });
  }

标签: javascriptangular

解决方案


buy() {
    return this.http
        .get("http://127.0.0.1:5000/razor_sub", {} )
        .subscribe(res => {
            const { id } = res;  
            if (id) {
                const options = getOptions(id);
                this.initPay(options);
            }
        }
    );
}
   
getOptions(subscription_id) {
    return {
        key: 'rzp_test_******',
        subscription_id,
        name: "Acme Corp.",
        ...
    }
};

initPay(options) {
    this.rzp = new this.winRef.nativeWindow['Razorpay'](options);
    this.rzp.open();
}

那是你需要的吗?


推荐阅读