可以通过以下代码解决:
::ng-deep .cdk-overlay-pane {
/* Change position to any of the following:
bottom, top, left, right, or center */
left: 50% !important;
transform: translateX(-50%) !important;
}
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-menu-example',
templateUrl: './menu-example.component.html',
styleUrls: ['./menu-example.component.css']
})
export class MenuExampleComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
这样,在mat-menu中设置的内容就可以在Button下面显示,并且居中对齐了。