angular 12+NG-ZORRO -UI中使用Modal对话框时注意

弹框的代码不能放在循环中不然就会出现黑屏了

 当时我的代码是这样写的,当然这是我的错误写法(特此记录)

<div class="pages">
    <button nz-button nzType="primary" class="addBtn">新建渠道</button>
    <div class="tableBox">
        <nz-table #basicTable [nzData]="listOfData">
            <thead>
              <tr>
                <th>Name</th>
                <th>Age</th>
                <th>Address</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
              <tr *ngFor="let data of basicTable.data">
                <td>{{ data.name }}</td>
                <td>{{ data.age }}</td>
                <td>{{ data.address }}</td>
                <td>
                    <button nz-button nzType="primary" (click)="showModal()">编辑</button>
                    <button nz-button nzType="primary" nzDanger nz-popconfirm nzPopconfirmTitle="确定删除吗?" (nzOnConfirm)="confirm()" [nzPopconfirmShowArrow]="false">删除</button>
                    <nz-modal
                    [(nzVisible)]="isVisible"
                    nzTitle="渠道编辑"
                    (nzOnCancel)="handleCancel()"
                    [nzFooter]="null"
                  >
                    <div *nzModalContent>
                      <form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm(validateForm.value)">
                        <nz-form-item>
                          <nz-form-label [nzSpan]="7" nzRequired>姓名</nz-form-label>
                          <nz-form-control [nzSpan]="12" nzHasFeedback nzValidatingTip="Validating..." [nzErrorTip]="userErrorTpl">
                            <input nz-input formControlName="userName" [ngModel]="userName" />
                            <ng-template #userErrorTpl let-control>
                              <ng-container *ngIf="control.hasError('required')">请输入您的姓名!</ng-container>
                              <ng-container *ngIf="control.hasError('duplicated')">The username is redundant!</ng-container>
                            </ng-template>
                          </nz-form-control>
                        </nz-form-item>
                        <nz-form-item>
                          <nz-form-label [nzSpan]="7" nzRequired>手机号</nz-form-label>
                          <nz-form-control [nzSpan]="12" nzHasFeedback >
                            <input nz-input formControlName="mobile" [ngModel] = "mobile" />
                          </nz-form-control>
                        </nz-form-item>
                        <nz-form-item>
                          <nz-form-label [nzSpan]="7" nzRequired>标识特征</nz-form-label>
                          <nz-form-control [nzSpan]="12" nzHasFeedback>
                            <input nz-input formControlName="channelCode" [ngModel] = "channelCode" />
                          </nz-form-control>
                        </nz-form-item>
                        <nz-form-item>
                          <nz-form-label [nzSpan]="7" nzRequired>计费方式</nz-form-label>
                          <nz-form-control [nzSpan]="12">
                            <nz-radio-group [(ngModel)]="radioValue" formControlName="radioGroup" >
                              <label nz-radio nzValue="CPA">CPA</label>
                              <label nz-radio nzValue="CPS">CPS</label>
                            </nz-radio-group>
                          </nz-form-control>
                        </nz-form-item>
                        <nz-form-item>
                          <nz-form-label [nzSpan]="7" nzRequired>有效判断</nz-form-label>
                          <nz-form-control [nzSpan]="12" nzHasFeedback>
                            <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择有效判断" [(ngModel)]="selectedValue" formControlName="effectiveJudgment">
                              <nz-option nzLabel="关注" nzValue="关注"></nz-option>
                              <nz-option nzLabel="打开小程序" nzValue="打开小程序"></nz-option>
                              <nz-option nzLabel="领外卖红包" nzValue="领外卖红包"></nz-option>
                            </nz-select>
                          </nz-form-control>
                        </nz-form-item>

                        <nz-form-item>
                          <nz-form-control [nzOffset]="8" [nzSpan]="8">
                            <button nz-button nzType="primary" [nzLoading]="isLoadingOne" nzBlock [disabled]="!validateForm.valid">保存</button>
                          </nz-form-control>
                        </nz-form-item>
                      </form>
                    </div>
                  </nz-modal>
                </td>
              </tr>
            </tbody>
        </nz-table>
    </div>
</div>

把弹框的代码拿到外层一切就ok了

<div class="pages">
    <button nz-button nzType="primary" class="addBtn">新建渠道</button>
    <div class="tableBox">
        <nz-table #basicTable [nzData]="listOfData">
            <thead>
              <tr>
                <th>Name</th>
                <th>Age</th>
                <th>Address</th>
                <th>Action</th>
              </tr>
            </thead>
            <tbody>
              <tr *ngFor="let data of basicTable.data">
                <td>{{ data.name }}</td>
                <td>{{ data.age }}</td>
                <td>{{ data.address }}</td>
                <td>
                    <button nz-button nzType="primary" (click)="showModal()">编辑</button>
                    <button nz-button nzType="primary" nzDanger nz-popconfirm nzPopconfirmTitle="确定删除吗?" (nzOnConfirm)="confirm()" [nzPopconfirmShowArrow]="false">删除</button>
                </td>
              </tr>
            </tbody>
        </nz-table>
    </div>
    <nz-modal
    [(nzVisible)]="isVisible"
    nzTitle="渠道编辑"
    (nzOnCancel)="handleCancel()"
    [nzFooter]="null">
    <div *nzModalContent>
      <form nz-form [formGroup]="validateForm" (ngSubmit)="submitForm(validateForm.value)">
        <nz-form-item>
          <nz-form-label [nzSpan]="7" nzRequired>姓名</nz-form-label>
          <nz-form-control [nzSpan]="12" nzHasFeedback nzValidatingTip="Validating..." [nzErrorTip]="userErrorTpl">
            <input nz-input formControlName="userName" [ngModel]="userName" />
            <ng-template #userErrorTpl let-control>
              <ng-container *ngIf="control.hasError('required')">请输入您的姓名!</ng-container>
              <ng-container *ngIf="control.hasError('duplicated')">The username is redundant!</ng-container>
            </ng-template>
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
          <nz-form-label [nzSpan]="7" nzRequired>手机号</nz-form-label>
          <nz-form-control [nzSpan]="12" nzHasFeedback >
            <input nz-input formControlName="mobile" [ngModel] = "mobile" />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
          <nz-form-label [nzSpan]="7" nzRequired>标识特征</nz-form-label>
          <nz-form-control [nzSpan]="12" nzHasFeedback>
            <input nz-input formControlName="channelCode" [ngModel] = "channelCode" />
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
          <nz-form-label [nzSpan]="7" nzRequired>计费方式</nz-form-label>
          <nz-form-control [nzSpan]="12">
            <nz-radio-group [(ngModel)]="radioValue" formControlName="radioGroup" >
              <label nz-radio nzValue="CPA">CPA</label>
              <label nz-radio nzValue="CPS">CPS</label>
            </nz-radio-group>
          </nz-form-control>
        </nz-form-item>
        <nz-form-item>
          <nz-form-label [nzSpan]="7" nzRequired>有效判断</nz-form-label>
          <nz-form-control [nzSpan]="12" nzHasFeedback>
            <nz-select nzShowSearch nzAllowClear nzPlaceHolder="请选择有效判断" [(ngModel)]="selectedValue" formControlName="effectiveJudgment">
              <nz-option nzLabel="关注" nzValue="关注"></nz-option>
              <nz-option nzLabel="打开小程序" nzValue="打开小程序"></nz-option>
              <nz-option nzLabel="领外卖红包" nzValue="领外卖红包"></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-control [nzOffset]="8" [nzSpan]="8">
            <button nz-button nzType="primary" [nzLoading]="isLoadingOne" nzBlock [disabled]="!validateForm.valid">保存</button>
          </nz-form-control>
        </nz-form-item>
      </form>
    </div>
    </nz-modal>
</div>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Angular,您可以使用ng-zorro-antd库的`nz-date-picker`组件来创建一个带有日历和日期范围的日期选择器。以下是一个使用`nz-date-picker`的例子: 1. 首先,您需要在您的应用安装和导入`ng-zorro-antd`库。 2. 在您的组件的HTML模板添加一个`nz-date-picker`元素,并使用`nzMode`属性将其定义为日期选择器。 ```html <nz-date-picker nzMode="date"></nz-date-picker> ``` 3. 在您的组件,您需要定义一个`nz-date-picker`对象,并将其与`nz-date-picker`元素相关联。您还可以使用`nzDisabledDate`属性来定义可选择的日期范围。 ```typescript import { Component } from '@angular/core'; import { NzDatePickerModule } from 'ng-zorro-antd/date-picker'; @Component({ selector: 'app-date-picker', templateUrl: './date-picker.component.html', styleUrls: ['./date-picker.component.css'] }) export class DatePickerComponent { disabledDate = (current: Date): boolean => { const minDate = new Date(2020, 0, 1); const maxDate = new Date(2020, 11, 31); return current < minDate || current > maxDate; } constructor() { } } ``` 在这个例子,我们定义了一个`disabledDate`函数来禁用不在2020年1月1日和2020年12月31日之间的日期。 4. 最后,您需要在`nz-date-picker`使用`nzFormat`属性来定义日期的格式。 ```html <nz-date-picker nzMode="date" nzFormat="yyyy-MM-dd" [nzDisabledDate]="disabledDate"></nz-date-picker> ``` 在这个例子,我们将日期格式定义为`yyyy-MM-dd`。 这就是如何在Angular使用ng-zorro-antd库的`nz-date-picker`组件创建一个带有日历和日期范围的日期选择器。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值