标签: angular-material-5

带有辅助按钮的mat-nav-list

我们如何在mat-nav-list内正确添加辅助按钮?

这是我的示例:

<mat-nav-list>
  <h3 matSubheader>This is the listview</h3>
    <a mat-list-item [routerLink]="['/detail']">
        <span matLine>Title</span>
        <button mat-icon-button (click)="onAdd()">
        <mat-icon>add</mat-icon>
    </button>
        <button mat-icon-button (click)="onRemove()">
        <mat-icon>delete</mat-icon>
    </button>
    </a>
</mat-nav-list>
Run Code Online (Sandbox Code Playgroud)

在这段代码中,我希望onAdd()or onRemove()可以单独执行,但是页面随后会导航。

工作演示

angular-material angular-material2 angular-material-5

3
推荐指数
1
解决办法
3770
查看次数

垫选择外部单击不起作用,下拉菜单关闭时

我已经使用Mat选择角度组件进行下拉,当我在下拉菜单(页面主体)之外单击时,需要触发一个事件。

<mat-select #select multiple (change)="onSubmit($event)" [(ngModel)]="emp">
    <mat-option *ngFor="let value of filter.default" [value]="value">
        {{value}}
    </mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)

这是我的ts文件

export class AnotherComponent {
  public text: String;

  @HostListener('document:click', ['$event'])
  clickout(event) {
    if(this.eRef.nativeElement.contains(event.target)) {
      console.log("clicked inside");
    } else {
      console.log("clicked outside");
    }
  }

  constructor(private eRef: ElementRef) {

  }
}
Run Code Online (Sandbox Code Playgroud)

它无法正常工作,请帮助

javascript angular angular5 angular-material-5

3
推荐指数
1
解决办法
3792
查看次数

如何在“ mat-sidenav”角材料5上放置“ mat-toolbar”

我写这篇文章是因为我对Angular Material的Mat Toolbar和Mat-sidenav有疑问。我试图使Sidenav进入工具栏,并且工具栏始终占据顶部,如下所示:

这是我的代码:

<mat-sidenav-container class="sidenav-container" autosize>
  <mat-sidenav #drawer class="sidenav" fixedInViewport="true"
      [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
      [mode]="(isHandset$ | async) ? 'side' : 'push'"
      [opened]="(isHandset$ | async)">
      <mat-toolbar class="fixed-header">
        <img class="logooTest" src="data:image/gif;base64,test"/>
      </mat-toolbar>
   		<mat-nav-list>
			  <mat-list-item>
				<a routerLink="/dashboard">Test</a>
        <mat-icon mat-list-icon>home</mat-icon>
        </mat-list-item>
        <mat-list-item>
          <a routerLink="/dashboard">Test</a>
          <mat-icon mat-list-icon>home</mat-icon>
          </mat-list-item>
          <mat-list-item>
          <a routerLink="/test">Test</a>
          <mat-icon mat-list-icon>tune</mat-icon>
          </mat-list-item>
            <mat-list-item>
            <a routerLink="/#">Test</a>
            <mat-icon mat-list-icon>settings</mat-icon>
            </mat-list-item>
            <mat-list-item>
            <a routerLink="/#">Test</a>
            <mat-icon mat-list-icon>layers</mat-icon>
            </mat-list-item>
            <mat-list-item (click)="showSubmenu = !showSubmenu" class="parent">
              <span class="full-width" *ngIf="isExpanded || isShowing">Test dropdown</span>
              <mat-icon mat-list-icon>flash_on</mat-icon>
              <mat-icon …
Run Code Online (Sandbox Code Playgroud)

angular-material angular-material2 angular angular5 angular-material-5

3
推荐指数
2
解决办法
5091
查看次数

如何在 mat-checkbox angular 5 中实现全选

这是我的 html 模板

<mat-card>
    <mat-card-content>
        <h2 class="example-h2">Select Employee</h2>    
        <section class="example-section">
            <mat-checkbox  [(ngModel)]="checked">Select All</mat-checkbox>
        </section>   
        <section class="example-section" *ngFor="let r of emp">
            <mat-checkbox class="example-margin" [(ngModel)]="checked">{{r.name}}</mat-checkbox>
        </section> 
    </mat-card-content>
</mat-card> 
Run Code Online (Sandbox Code Playgroud)

这是代码工作不正常,如果我点击全选,它选择所有复选框,如果我选择单个复选框,它也选择所有项目。

请帮忙。

javascript angular angular5 angular-material-5

2
推荐指数
1
解决办法
1万
查看次数

如何导入 Angular Material Css

我正在尝试在我的项目中使用 Angular Material 并且导入了标签,但并非所有样式都在那里。

在我的 HTML 中:

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker startView="year" [startAt]="startDate"></mat-datepicker>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

它应该显示:

在此处输入图片说明

但它显示:

在此处输入图片说明

我添加@import "~@angular/material/prebuilt-themes/indigo-pink.css";到 style.css 并且日历显示正常,但文本字段看起来仍然很糟糕。

在此处输入图片说明

angular-material angular-material2 angular-material-5

2
推荐指数
1
解决办法
1万
查看次数

选择角度材质模态中的第二个按钮

我有一个简单的有角材料模态。我想在打开/加载时聚焦“是”按钮。tabindex='-1'我确实通过在提供程序中设置“否”按钮来实现这一点autoFocus: true。然而,这会导致用户体验问题,即您无法使用键盘聚焦“否”按钮。如何聚焦第二个按钮,同时保持可通过键盘访问它。我也尝试过使用tabindex,这似乎并没有影响选择。我正在寻找一个优雅的解决方案(所以最好不要编写一些打字稿来解决它)

对话框.组件.html

<h2 mat-dialog-title>Cookie request</h2>
<mat-dialog-content>Should we use a cookie to automatically log you in next time?</mat-dialog-content>
<mat-dialog-actions>
  <button mat-button [mat-dialog-close]='false' tabindex='-1'>No</button>
  <button mat-button [mat-dialog-close]="true"  tabindex='1'>Yes</button>
</mat-dialog-actions>
Run Code Online (Sandbox Code Playgroud)

摘自 app.module.ts

@NgModule({
  declarations: [...stuff],
  imports: [...stuff],
  providers: [
    {provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: true, disableClose: true, autoFocus: true }}
  ],
  entryComponents: [
    DialogComponent
  ],
  bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)

官方文档: https: //material.angular.io/components/dialog/api

可选:如何强制焦点留在我的模式中,直到它关闭?

html angular angular-material-5

2
推荐指数
1
解决办法
3374
查看次数

启动时角度材质对话框组件滚动问题

我在我的应用程序中使用 Angular Material Dialog 组件,并在此对话框中,我向用户呈现一个可能有滚动条的 HTML 数据表。

但我的问题是,当我单击按钮打开实际对话框时,我注意到内容立即滚动到底部,这很麻烦,因为我需要手动滚动回顶部。

我正在使用此处描述的标准设置:

https://material.angular.io/components/dialog/overview

我的对话调用如下:

myDialog(a: string, b: string) {
        let dialogRef = this.dialog.open(MyDialogComponent, {
            height: '500px',
            width: '800px',
            data: { a,b }
        });
}
Run Code Online (Sandbox Code Playgroud)

我该如何避免滚动到底部的问题?我尝试过一些CSS,例如top: 0; position: fixed;但无济于事。

css angular-material angular angular-material-5

1
推荐指数
1
解决办法
1万
查看次数

内置的deselectAll方法无法在多个Angular Mat-Selection-List中使用

我正在使用angular5 mat-selection-list在同一组件中创建多个组件。

list-selection-example.html

 Shoes: 
<mat-selection-list #shoes>
  <mat-list-option *ngFor="let shoe of typesOfShoes" 
                   [value]="shoe">
    {{shoe}}
  </mat-list-option>
</mat-selection-list>

<button mat-button  (click)="deselectShoes()">Deselect all Shoes</button>

Cloths: 
<mat-selection-list #cloths>
  <mat-list-option *ngFor="let cloth of typesOfCloths" 
                   [value]="cloth">
    {{cloth}}
  </mat-list-option>
</mat-selection-list>

<button mat-button  (click)="deselectCloth()">Deselect all Cloths</button>
Run Code Online (Sandbox Code Playgroud)

列表选择示例

export class ListSelectionExample {
  typesOfShoes = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];

  typesOfCloths = ['Amaxa', 'Cotton', 'Woolen', 'Nylon'];

    @ViewChild(MatSelectionList) shoes: MatSelectionList;
    @ViewChild(MatSelectionList) cloths: MatSelectionList;


  deselectShoes(){
    this.shoes.deselectAll(); 
  }

  deselectCloth(){
    this.cloths.deselectAll(); 
  }
  ngOnInit(){

  }
}
Run Code Online (Sandbox Code Playgroud)

这是完整的代码:https : //stackblitz.com/edit/angular-i3pfu2-dla3rd?file=app%2Flist-selection-example.ts

在此示例中,deselectShoes()方法按预期工作。但deselectCloth()在 …

angular-material angular-material2 angular angular5 angular-material-5

0
推荐指数
1
解决办法
1628
查看次数