【发布时间】:2018-05-07 04:24:03
【问题描述】:
我正在努力完成这项工作,但找不到如何做到这一点
我有一个带有两个按钮是和否的代码。我想要做的是,一旦我点击是按钮,成功消息应该打印在页面上(不是弹出窗口),同样没有按钮也应该显示消息。有没有办法用 javascript 或 bootstrap 来做?
confirmation.component.html
<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
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
<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>
【问题讨论】:
-
您到底在哪里使用这个
confirmation组件?您能否也为该组件添加模板? -
@SiddharthAjmera 我也添加了该组件
-
不确定是否理解,是或否后要在users.component.html中打印一些信息吗?
-
yes 在单击是或否按钮后,应在 users.component 页面中显示一些消息
-
点击后我只需要一个“是”按钮的功能..我需要一个成功的警报消息,如果可以,请指导我如何做到这一点
标签: javascript html twitter-bootstrap angular