标签: angular-material2

角度2:阻止用户在模态对话框外单击

我想阻止用户在模态对话框外单击,他只能按下按钮退出对话框.我怎样才能做到这一点?

dialog.component.ts

ngOnInit() {

const dialogRef = this.dialog.open(DialogResultComponent);
dialogRef.afterClosed().subscribe(result => {
  console.log(result);
});
Run Code Online (Sandbox Code Playgroud)

}

对话框的result.component.ts

    import { Component, OnInit } from '@angular/core';
import { MdDialog, MdDialogRef } from '@angular/material';
import { FormGroup,FormControl,Validators,FormBuilder,  } from '@angular/forms';



@Component({
  selector: 'app-dialog-result',
  templateUrl: './dialog-result.component.html',
})

export class DialogResultComponent {


  form: FormGroup;
  name = new FormControl('',Validators.required);
  width = new FormControl('',Validators.required);
  height = new FormControl('',Validators.required);
  constructor(public dialogRef: MdDialogRef<DialogResultComponent>,private fb: FormBuilder) {

  }

  ngOnInit() {
  this.form = this.fb.group({
      'name' :this.name,
      'width':   this.width,
      'height':  this.height,
    });
}

  saveData(){ …
Run Code Online (Sandbox Code Playgroud)

css modal-dialog angular-material2 angular

8
推荐指数
2
解决办法
9942
查看次数

如何使用带有Angular 2/4的材质将html传递给模板对话框组件

我想将自定义html从特定页面传递到模板组件,以便使用Material(MdDialog)创建对话框.直到现在我可以将简单数据传递给模板,如下所示:

    import { Component, OnInit, Input, TemplateRef } from '@angular/core';
    import { MdDialog, MdDialogConfig, MdDialogRef } from '@angular/material';
    import { DialogComponent } from './dialog.component';


    @Component({
      selector: 'app-commoncontent',
      template: '
       <div class="row  pull-right">
         <button md-raised-button (click)="open()" >{{"addButton" | translate}}
         </button>
       </div>',
      styleUrls: ['./commoncontent.component.css']
    })
    export class CommoncontentComponent implements OnInit {
      constructor(public dialog : MdDialog) { }

      ngOnInit() {
      }

      open() {
          let config = new MdDialogConfig()
          let dialogRef:MdDialogRef<DialogComponent> = 
          this.dialog.open(DialogComponent, config);
          dialogRef.componentInstance.content = "Hello Angular"

      }
    }

    import { Component, OnInit, …
Run Code Online (Sandbox Code Playgroud)

material angular-material2 angular

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

无法在Angular 4中编译材料,给出:/ material"没有导出的成员'MaterialModule

我正在使用Material UI Framework创建新的Angular 4应用程序.我按照以下步骤操作:https://material.angular.io/guide/getting-started .

但是,当我在'npm start'时,它无法编译并说: ERROR in /home/programoholic/workspace/heroapp/src/app/app.module.ts (3,10): Module '"/home/programoholic/workspace/heroapp/node_modules/@angular/material/material"' has no exported member 'MaterialModule'.

错误截图:

编译时遇到此错误

这是我的Package.Json文件:

{
  "name": "heroapp",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/cdk": "^2.0.0-beta.11",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/material": "^2.0.0-beta.11",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "core-js": "^2.4.1", …
Run Code Online (Sandbox Code Playgroud)

angular-material2 angular

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

在角度/材料中找不到导出材料模块

我按照指南安装了https://github.com/isaacplmann/ngx-tour模块并进行了集成,但是我export materialmodule was not found in angular/material 在npm start或build中遇到了其他类似的错误.这可能是什么问题,如何解决.我已经检查了包,所有都已安装.

谢谢

angular-material angular-material2 angular

8
推荐指数
2
解决办法
8483
查看次数

角度材质对话框返回值

我有一个以下对话框组件(我在另一个组件中使用dialog.open(MyDialogComponent)打开).

export class MyDialogComponent implements OnInit {
  constructor(public matDialogRef: MatDialogRef<MyDialogComponent>) {}

  ngOnInit() {}
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过执行绑定到对话框组件中按钮的matDialogRef.close(dataToReturn)将任何数据返回给调用组件.但是,如果用户点击其他地方但弹出窗口关闭它,我怎么能返回数据呢?

dialog angular-material2 angular

8
推荐指数
3
解决办法
7820
查看次数

Angular Material 2 Card Header按钮设置正确

我使用Angular Material 2,我想要一个卡片头图标按钮.如何将按钮设置在右侧?

我的计划: 在此输入图像描述

当前网站: 在此输入图像描述

我想在标题中设置按钮rop.我该怎么做?我排除了类别代码,因为没有问题.在打字稿中,代码只是一个for循环来添加更多卡片和一个虚拟方法来点击卡片.

.healthy-search {
    width: 100%
}

.healthy-card {
    margin-right: 5px;
    margin-bottom: 5px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="flex-container" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
  <div class="flex-item" fxFlex="90%" fxFlex.xs="90%">
    <mat-form-field class="healthy-search">
      <textarea matInput placeholder="Suche"></textarea>
    </mat-form-field>
  </div>
</div>
<div class="flex-container" fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
  <div class="flex-item" fxFlex="85%" fxFlex.xs="85%">
    <mat-expansion-panel>
    
     <!-- Here is the Category -->
     

     <!--Elements of Category -->

      <div class="flex-container" fxLayoutWrap fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center center" fxLayoutAlign.xs="start">
        <div class="flex-item healthy-card" fxFlex="400px" *ngFor="let number of numbers" (click)="cardClick()">
          <mat-card class="example-card">
            <mat-card-header>
              <mat-card-title>Title …
Run Code Online (Sandbox Code Playgroud)

angular-material2 angular-flex-layout angular

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

角度材料对话框和热模块重新加载

到目前为止,我已成功完成以下工作:

✓HMR(热模块重新加载)设置
✓角度(5)和材料运行良好
✓打开一个对话框(下面的代码片段)

// ...
constructor(private dialog: MatDialog){}
//...
public openDialog(){
    this.dialogRef = this.dialog.open(someDialogComponent, {
      width: '300px'
    });
}
Run Code Online (Sandbox Code Playgroud)

✓在对话框或对话框的父控制器上进行更改
✓MMR被触发(yay)
✖对话框挂起死机状态,由于对话框和背景被"卡住"而无法点击,页面基本上被冻结

我试图挂钩ngOnInitngOnDestroy在父或对话框控制器中关闭对话框引用,如果存在,我也尝试过dialog.closeAll(),但这没有用.此外,理想情况下,对话框不必关闭,但我似乎无法修复此僵尸对话框问题.

有没有遇到过这个?

webpack-hmr angular-material2 angular

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

Angular 4材料芯片占位符不能正常工作

我试图用可选择和可移动的选项实现角度垫片.但问题是占位符在加载时移动到顶部.我不知道我在代码上做了什么错.请有人帮我解决这个问题.

在下面添加了GIF

在此输入图像描述 我的代码是

<mat-form-field>
  <mat-chip-list #chipList>
    <mat-chip *ngFor="let keyword of keywords" [selectable]="selectable"
             [removable]="removable" (remove)="remove(keyword)">
      {{keyword}}
      <mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
    </mat-chip>
    <input placeholder="Keywords"
           [matChipInputFor]="chipList"
           [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
           [matChipInputAddOnBlur]="addOnBlur"
           (matChipInputTokenEnd)="add($event)" />
  </mat-chip-list>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)

ts

  visible: boolean = true;
  selectable: boolean = true;
  removable: boolean = true;
  addOnBlur: boolean = true;
  separatorKeysCodes = [ENTER, COMMA];
  keywords= [];   // At time load i need this to be empty


public add(event: MatChipInputEvent): void {
    let input = event.input;
    let value = event.value;
    if ((value || '').trim()) …
Run Code Online (Sandbox Code Playgroud)

typescript angular-ui angular-material angular-material2 angular

8
推荐指数
2
解决办法
2921
查看次数

如何过滤mat-tree组件Angular Material 6.0.1

我正在使用垫树角材料组件.这是一个很好的组件,有一些非常有用的功能,如多选,全部展开/全部折叠.我无法在任何API中找到任何树过滤功能.有没有人遇到这个功能或做任何工作来获得mat-tree过滤器?

在此输入图像描述

tree filter angular-material2 angular angular6

8
推荐指数
4
解决办法
8783
查看次数

选择所有垫选项并取消选择全部

我的情况如下:

在此输入图像描述

我想要实现的是:

  1. 当用户单击All时,将选择所有选项,当用户再次单击All时,将取消所有选项.
  2. 如果所有选项被选中,并单击用户比任何其他复选框, All然后所有,并点击复选框将被取消.
  3. 当用户逐个选择4个选项时,则选择All.

HTML文件

<mat-select placeholder="User Type" formControlName="UserType" multiple>
    <mat-option *ngFor="let filters of userTypeFilters" [value]="filters.key">
          {{filters.value}}
    </mat-option>
        <mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)

TS文件

this.searchUserForm = this.fb.group({
  userType: new FormControl('')
});

userTypeFilters = [
  {
    key: 1, value: 'Value 1',
  },
  {
    key: 2, value: 'Value 2',
  },
  {
    key: 3, value: 'Value 3',
  },
  {
    key: 4, value: 'Value 4',
  }
]

toggleAllSelection() {
  if (this.allSelected.selected) {
    this.searchUserForm.controls.userType …
Run Code Online (Sandbox Code Playgroud)

multi-select angular-material2 angular6

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