import { Component, OnInit } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; @Component({ selector: 'app-response-toolbar-demo', templateUrl: './response-toolbar-demo.component.html' }) export class ResponseToolbarDemoComponent implements OnInit { data2 = [ { id: 'toolbar-001', text: '新增', class: 'btn-primary', disabled: false }, { id: 'toolbar-002', text: '禁用', disabled: true }, { id: 'toolbar-115', text: '第二层', class: 'btn-warning', dropdownCls: 'bg-success', isDP: true, placement: 'top', children: [ { id: 'toolbar-116', text: '打印' }, ..... ] }, .... ]; data = [ { id: 'toolbar-2-001', text: '新增', class: 'btn-primary', disabled: false }, ...... ]; // 按钮可见状态 btnVisible = new BehaviorSubject({}); // 按钮禁用状态 btnDisable = new BehaviorSubject({}); constructor() {} ngOnInit() {} /** * 验证按钮的禁用状态变化 */ modifyDisableState() { this.btnDisable.next({ 'toolbar-001': true, 'toolbar-002': false, 'toolbar-115': true }); } /** * 验证按钮的是否显示 */ modifyVisableState() { this.btnVisible.next({ 'toolbar-001': false, 'toolbar-002': false }); } responseToolbarClick(ev) { console.log('恭喜您选中了ID' + ev['id'] + '文字内容为' + ev['text']); } }