首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >告警成功和告警危险消息按钮

告警成功和告警危险消息按钮
EN

Stack Overflow用户
提问于 2017-11-23 17:10:24
回答 1查看 709关注 0票数 0

我正在努力地完成这件事,但找不到怎么做

我有一个有两个按钮的代码,是和否。我正在尝试做的是,一旦我点击了yes按钮,成功的消息应该打印在页面上(而不是弹出),同样的方式no按钮也应该显示一条消息。有没有什么方法可以用javascript或bootstrap来实现呢?

confirmation.component.html

代码语言:javascript
复制
<div class="modal fade" id="confirmationModal" role="dialog">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
        <p>{{confirmationMessage}}</p>
        <button type="button" data-dismiss="modal" class="btn btn-success" (click)="emitAction(true)">Yes</button>
        <button type="button" data-dismiss="modal" class="btn btn-danger" (click)="emitAction(false)">No</button>
      </div>
    </div>
  </div>
</div>

confirmation.components.ts

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { Input, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'app-confirmation',
  templateUrl: './confirmation.component.html',
  styleUrls: ['./confirmation.component.css']
})
export class ConfirmationComponent implements OnInit {

  @Output() action:EventEmitter<Boolean> = new EventEmitter<Boolean>();
  @Input() confirmationMessage;
  constructor() { }

  ngOnInit() {

  }

  emitAction(isConfirmed:Boolean){
    this.action.emit(isConfirmed)
  }

}

users.component.html

代码语言:javascript
复制
<div class="container">   <h2>Active Users</h2>   <hr>   <table datatable  [dtTrigger]="dtTrigger" class="table table-striped table-bordered hover">
    <thead>
      <tr>
        <th>Username</th>
        <th>Email</th>
        <th>Status</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody *ngIf="!showLoader">
      <tr *ngFor="let user of users">
        <td>{{user.local.username}}</td>
        <td>{{user.local.email}}</td>
        <td>
          <div *ngIf="user.local.sub_end_dt && (user.local.sub_end_dt| amDifference : dateTo : 'days')>=0">
            <span style="color: green;">{{(user.local.sub_end_dt| amDifference : dateTo : 'days')>=0?"Active":""}}</span>
            <br>
            <span>{{(user.local.sub_end_dt| amDifference : dateTo : 'days')}} Days Remaining</span>
          </div>
          <span style="color: red;">{{(user.local.sub_end_dt| amDifference : dateTo : 'days')<0||!user.local.sub_end_dt?"Expired":""}}</span>  
        </td>
        <td>
          <i class="fa fa-clipboard" aria-hidden="true" style="cursor: pointer;" (click)="copyPassword(user.local.password)" title="Copy Password"></i>
          |<i class="fa fa-trash-o" aria-hidden="true" (click)="setAction('delete',user,'Do you wish to delete the user?')" data-toggle="modal" data-target="#confirmationModal"  style="color: red; cursor: pointer;" title="Delete User"></i>
          |<i class="fa fa-ban" *ngIf="user.local.sub_active" (click)="setAction('disable',user,'Do you wish to disable the user?')" data-toggle="modal" data-target="#confirmationModal"  aria-hidden="true" style="color: orange;cursor: pointer;" title="Disable User" ></i>
          <i class="fa fa-check" *ngIf="!user.local.sub_active" (click)="setAction('enable',user,'Do you wish to enable the user?')" data-toggle="modal" data-target="#confirmationModal"  aria-hidden="true" style="color: green;cursor: pointer;" title="Enable User"></i>
          |<i class="fa fa-user-secret" *ngIf="!user.admin" (click)="setAction('enableAdmin',user,'Do you wish to grant admin role to user?')" data-toggle="modal" data-target="#confirmationModal" aria-hidden="true" style="cursor: pointer;" title="Make User Admin"></i>
          <i class="fa fa-user" style="color: grey;cursor: pointer;" *ngIf="user.admin" (click)="setAction('disableAdmin',user,'Do you wish to disable admin access for user?')"  data-toggle="modal" data-target="#confirmationModal" title="Disable Admin User" aria-hidden="true"></i>
          |<i class="fa fa-user-plus" aria-hidden="true" style="color: blue;cursor: pointer;" *ngIf="!user.support" (click)="setAction('enableSupport',user,'Do you wish to assign support to user?')" data-toggle="modal" data-target="#confirmationModal"  title="Assign Support"></i>
          <i class="fa fa-user-times" aria-hidden="true" data-toggle="modal" data-target="#confirmationModal" style="color: orange;cursor: pointer;" *ngIf="user.support" (click)="setAction('disableSupport',user,'Do you wish to disable support for user?')" title="Disable Support"></i>
        </td>
        </tr>
      </tbody>
    </table>
    <div style="text-align: center;" *ngIf="showLoader">
        <i class="fa fa-spinner fa-5x fa-spin" aria-hidden="true"></i>
    </div> </div> <app-confirmation (action)="action($event)" [confirmationMessage]="message"></app-confirmation>
EN

回答 1

Stack Overflow用户

发布于 2017-11-23 17:54:53

定义新模型:

代码语言:javascript
复制
export class ConfirmationMessage{
message: string;
result: boolean;
}

在confirmation.component.ts中

代码语言:javascript
复制
import { Component, OnInit } from '@angular/core';
import { Input, Output, EventEmitter } from '@angular/core';
import { ConfirmationMessage } from ./confirmation-message';

@Component({
  selector: 'app-confirmation',
  templateUrl: './confirmation.component.html',
  styleUrls: ['./confirmation.component.css']
})
export class ConfirmationComponent implements OnInit {

  @Output() action:EventEmitter<ConfirmationMessage> = new EventEmitter<ConfirmationMessage>();
  @Input() confirmationMessage;
  constructor() { }

  ngOnInit() {

  }

  emitAction(isConfirmed:Boolean){
    confirmation: ConfirmationMessage = new ConfirmationMessage();
    confirmation.result = isConfirmed;
    if(isConfirmed)
       confirmation.message ="ok";
    else
       confirmation.message = "no";
    this.action.emit(confirmation);
  }

}

在users.component.html中

代码语言:javascript
复制
 <app-confirmation (action)="actionElaborate($event)" [confirmationMessage]="message"></app-confirmation>
...
<p >{{messageToShow}}</p> //here to show an alert you can use bootstrap alert and show it or not with ngIf

在users.component.ts中

代码语言:javascript
复制
private messageToShow: string = "";

actionElaborate(ev){
   if(ev != null){
     this.messageToShow = "";    
   }else{
      ...
      confirmation: ConfirmationMessage = ev;
      this.messageToShow = confirmation.message;
   }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47451497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档