NzModalService如何给动态加载的组件传值

使用nzComponentParams

nzComponentParams: {
    key1: value1,
    key2: value2,
    ...
}

在组件editdComponent中接收值的方法

@Input() key1;
@Input() key2;

以下是例子哦

HTML页面

<button (click)="dialog()">打开弹框</button>

TS文件

import { Component,OnInit, ViewContainerRef } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd/modal';
import { DialogComponent} from './dialog/dialog.component'
@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.scss']
})
export class ParentComponent implements OnInit {
  constructor(private modal: NzModalService) { }  
  
  content:any='我是需要传递给弹出框的值'

  ngOnInit(): void {}
  
  dialog(){
    this.modal.create({
      nzTitle:'11111',
      nzContent: DialogComponent,
      nzClosable: false,
      nzComponentParams:{
        key:this.content,
      },
      nzOnOk: () => new Promise(resolve => setTimeout(resolve, 1000)),
    });
  } 

}

弹窗页面
HTML

{{key}}

TS

import { Component, OnInit,Input } from '@angular/core';
@Component({
  selector: 'app-dialog',
  templateUrl: './dialog.component.html',
  styleUrls: ['./dialog.component.scss']
})
export class DialogComponent implements OnInit {
  @Input() key:any;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import { HttpClient, HttpRequest, HttpResponse, HttpParams, HttpHeaders, } from '@angular/common/http'; import { NzMessageService, NzModalService, UploadFile } from 'ng-zorro-antd'; import { _HttpClient } from '@delon/theme'; import { Route, Router, ActivatedRoute, Params } from '@angular/router'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Component, OnInit } from '@angular/core'; import {throttleTime} from "rxjs/operators"; import {debounceTime} from "rxjs-compat/operator/debounceTime"; @Component({ selector: 'zjcx', templateUrl: './zjcx.component.html', }) export class ZjcxComponent implements OnInit { pageIndex = 1; pageSize = 10; total = 0; data: any[] = []; loading = false; q = { pageIndex: 1, pageSize: 10, yhzh: '', zhmc: '', dfyhzh: '', dfzhmc: '', maxje: '' , minje: '', jysj: '', }; constructor( private http: _HttpClient, private httpClient: HttpClient, public msg: NzMessageService, private modalSrv: NzModalService, public router: Router, private fb: FormBuilder, ) { } ngOnInit() { this.msg.error("暂无数据"); } searchData(reset: boolean = false) { if (reset) { this.pageIndex = 1; } const yhzh = this.q.yhzh===null ? '':this.q.yhzh; const zhmc = this.q.zhmc===null ? '':this.q.zhmc; const dfyhzh = this.q.dfyhzh===null ? '':this.q.dfyhzh; const dfzhmc = this.q.dfzhmc===null ? '':this.q.dfzhmc; const minJe = this.q.minje===null ? '':this.q.minje; const maxJe = this.q.maxje===null ? '':this.q.maxje; const jysj = this.q.jysj===null ? '':this.q.jysj; const params = new HttpParams() .set('yhzh', yhzh) .set('zhmc', zhmc) .set('dfyhzh', dfyhzh) .set('dfzhmc', dfzhmc) .set('minJe', minJe) .set('maxJe', maxJe) .set('jysj', jysj) .set('pageIndex',''+this.pageIndex) .set('pageSize', ''+this.pageSize); this.loading=true; this.http .post('/download/zjfx/zjcx/getZjxx', params) .pipe(throttleTime(1000)) .subscribe((res: any) => { this.data = res.list; this.total = res.total; this.loading = false; },() => { this.loading = false; this.msg.error('任务查询失败,请重新再试!'); }); } }根据这个代码修改一下
05-31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值