如何清除angular2中的密码

时间:2018-05-14 10:45:22

标签: angular

enter image description here这里我上传了我的html和ts页面。这段代码的逻辑是当我们点击删除操作的删除按钮时,会显示一条弹出消息,我们要输入密码来删除该特定的字段,我点击一个问题,当我点击按钮删除它被删除的特定字段,但再次显示相同的密码,以删除另一个字段。请给我一个适当的解决方案来解决这个问题。谢谢。< / p>

        HTML
        <button type="button"
                                            class="btn btn-outline-danger btn-sm icmn-bin" 
                                            data-toggle="modal" data-name="{{source_info.source.name}}"  
                                            [attr.data-target]="'#delete_modal_' + source_info.source.name"  (click)="clear()"
                                            *ngIf="source_info.source.assigned ===  false"></button>  


    <!--  bootstrap modal starts -->
                                    <div class="modal fade modal-size-small delete-modal" id="delete_modal_{{source_info.source.name}}" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="myModalLabel">Are You Sure to
                                                        Delete ?</h5>
                                                    <button data-dismiss="modal" type="button">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <div class="modal-body">
                                                    <div class="row">
                                                        <div class="col">
                                                            <div class="form-group">
                                                                <h6>Enter Your password to confirm Delete <strong>{{source_info.source.name}}</strong></h6>
                                                                <input class="form-control input-pos" name="password" 
                                                                    [(ngModel)]="password" type="password" />
                                                            </div>
                                                            <div class="form-group pull-right">
                                                            <!--    <button class="btn btn-primary btn-sm" data-dismiss="modal"
                                                                    type="button">Cancel</button>  -->
                                                                <button class="btn btn-danger btn-sm"
                                                                    (click)="name=source_info.source.name;deleteSource(name, password)">Delete</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <!--  bootstrap modal ends -->

TS
  deleteSource(name, password) {
    const headers = new Headers({'Authorization': localStorage.getItem('Token'), 'Content-Type': 'application/json'});
    const options = new RequestOptions({headers: headers});
    console.log(name, password);

    $('.delete-modal').modal('hide');
    if (password === localStorage.getItem('Password')) {
      this.service.delete(options, services.data_source_service + name).subscribe((response) => {
        this.message.handle('icmn-checkmark', '', 'Data source has been deleted', 'success');
        this.getSources();
      }, (err) => {
        this.message.errorHandler(err);
      })
    } else {
      this.password = '';
      $.notify({
        message: 'Password not valid for delete operation!'
      },
        {
          type: 'warning'
        })
    }
  }

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您需要在模式中输入密码以清除数据源。输入密码并删除数据源后,密码字段应该再次为空,因此您必须在下次删除时再次输入密码字段,但是如果您输入密码字段将保留在字段中并且在删除操作后不会被清除

解决方案是在 09:42:35 [ERROR] Failed to execute goal on project hybris-package: Could not resolve dependencies for project com.sap:hybris-package:jar:1.0-SNAPSHOT: Could not transfer artifact com.sap.hybris:hybris-commerce-suite:zip:6.6.0.1 from/to thirdparty (https://nexus.tech/nexus/content/repositories/thirdparty): GET request of: com/sap/hybris/hybris-commerce-suite/6.6.0.1/hybris-commerce-suite-6.6.0.1.zip from thirdparty failed: SSL peer shut down incorrectly -> [Help 1] 文件中只添加一行代码。删除操作成功后,您必须将密码设置回空字符串。这必须在.ts函数内完成。

subscribe

每次成功删除后,尝试删除下一个数据时,密码字段应再次为空。

编辑 - 关闭时清除密码

现在,当我们在不按下按钮的情况下关闭模态时,密码字段仍将被填充。因此,当我们按下关闭按钮时,我们必须做同样的事情。我们可以为这个按钮添加一个按下时执行的功能。

if (password === localStorage.getItem('Password')) {
  this.service.delete(options, services.data_source_service + name).subscribe((response) => {
    this.message.handle('icmn-checkmark', '', 'Data source has been deleted', 'success');
    this.getSources();

    // SET PASSWORD TO EMPTY STRING HERE
    this.password = '';
  }, (err) => {
    this.message.errorHandler(err);
  })
} else {
  this.password = '';
  $.notify({
    message: 'Password not valid for delete operation!'
  },
    {
      type: 'warning'
    })
}

在我们的打字稿文件中,我们现在只需在此函数内再次清除密码。

<button data-dismiss="modal" type="button" (click)="onModalClose()">
    <span aria-hidden="true">&times;</span>
</button>

我不是百分之百确定这个函数是否会覆盖dismiss函数,但我认为它应该同时执行,关闭模态并执行onModalClose(){ this.password=''; }