我想阻止用户在模态对话框外单击,他只能按下按钮退出对话框.我怎样才能做到这一点?
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) 我想将自定义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 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) 我按照指南安装了https://github.com/isaacplmann/ngx-tour模块并进行了集成,但是我export materialmodule was not found in angular/material 在npm start或build中遇到了其他类似的错误.这可能是什么问题,如何解决.我已经检查了包,所有都已安装.
谢谢
我有一个以下对话框组件(我在另一个组件中使用dialog.open(MyDialogComponent)打开).
export class MyDialogComponent implements OnInit {
constructor(public matDialogRef: MatDialogRef<MyDialogComponent>) {}
ngOnInit() {}
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过执行绑定到对话框组件中按钮的matDialogRef.close(dataToReturn)将任何数据返回给调用组件.但是,如果用户点击其他地方但弹出窗口关闭它,我怎么能返回数据呢?
我使用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)到目前为止,我已成功完成以下工作:
✓HMR(热模块重新加载)设置
✓角度(5)和材料运行良好
✓打开一个对话框(下面的代码片段)
// ...
constructor(private dialog: MatDialog){}
//...
public openDialog(){
this.dialogRef = this.dialog.open(someDialogComponent, {
width: '300px'
});
}
Run Code Online (Sandbox Code Playgroud)
✓在对话框或对话框的父控制器上进行更改
✓MMR被触发(yay)
✖对话框挂起死机状态,由于对话框和背景被"卡住"而无法点击,页面基本上被冻结
我试图挂钩ngOnInit和ngOnDestroy在父或对话框控制器中关闭对话框引用,如果存在,我也尝试过dialog.closeAll(),但这没有用.此外,理想情况下,对话框不必关闭,但我似乎无法修复此僵尸对话框问题.
有没有遇到过这个?
我试图用可选择和可移动的选项实现角度垫片.但问题是占位符在加载时移动到顶部.我不知道我在代码上做了什么错.请有人帮我解决这个问题.
在下面添加了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
我的情况如下:
我想要实现的是:
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) angular ×9
angular6 ×2
angular-ui ×1
css ×1
dialog ×1
filter ×1
material ×1
modal-dialog ×1
multi-select ×1
tree ×1
typescript ×1
webpack-hmr ×1