我正在使用mat-table.它有一个过滤器,可以正常使用doc示例:
从https://material.angular.io/components/table/overview,原始代码是:
<div class="example-header">
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">
</mat-form-field>
</div>
<mat-table #table [dataSource]="dataSource">
<!-- the rest of the code -->
</mat-table>
Run Code Online (Sandbox Code Playgroud)
export class TableFilteringExample {
displayedColumns = ['position', 'name', 'weight', 'symbol'];
dataSource = new MatTableDataSource(ELEMENT_DATA);
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // MatTableDataSource defaults to lowercase matches
this.dataSource.filter = filterValue;
}
}
const ELEMENT_DATA: Element[] = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, …Run Code Online (Sandbox Code Playgroud) 我有一个可以从父母和孩子编辑的变量.
parent.html:
<div *ngIf="editEnabled">
<mat-icon (click)="disableEdit()">cancel</mat-icon>
</div>
<child [(editEnabled)]="editEnabled"></child>
Run Code Online (Sandbox Code Playgroud)
parent.ts:
export class ParentComponent {
editEnabled: boolean;
disableEdit(){
this.editEnabled = false;
}
}
Run Code Online (Sandbox Code Playgroud)
Child.html:
<div *ngIf="!editEnabled">
<mat-icon (click)="enableEdit()">settings</mat-icon>
</div>
Run Code Online (Sandbox Code Playgroud)
child.ts
private _editEnabled: boolean;
@Input()
set editEnabled(value: boolean) {
this._editEnabled = value;
}
get editEnabled(): boolean {
return this._editEnabled;
}
enableEdit(){
this.editEnabled = true;
}
Run Code Online (Sandbox Code Playgroud)
但我不能在两个组件之间通信editEnabled.
我的错误在哪里?
我有一个字典列表,我想获得那些在一个键中具有相同值的字典:
my_list_of_dicts = [{
'id': 3,
'name': 'John'
},{
'id': 5,
'name': 'Peter'
},{
'id': 2,
'name': 'Peter'
},{
'id': 6,
'name': 'Mariah'
},{
'id': 7,
'name': 'John'
},{
'id': 1,
'name': 'Louis'
}
]
Run Code Online (Sandbox Code Playgroud)
我想保留那些具有相同“名称”的项目,因此,我想获得以下内容:
duplicates: [{
'id': 3,
'name': 'John'
},{
'id': 5,
'name': 'Peter'
},{
'id': 2,
'name': 'Peter'
}, {
'id': 7,
'name': 'John'
}
]
Run Code Online (Sandbox Code Playgroud)
我正在尝试(未成功):
duplicates = [item for item in my_list_of_dicts if len(my_list_of_dicts.get('name', None)) > 1]
Run Code Online (Sandbox Code Playgroud)
我清楚这段代码的问题,但不能做正确的句子
我正在使用 wkhtmltopdf 打印我的 html 代码,此代码有传单地图,我的问题是 pdf 文件无法正确打印地图,似乎它不等待地图,所以我包含了一个窗口状态条件,但没有成功:
在我的html中:
var myMap = L.map('myMap',{attributionControl: false, zoomControl:false })
.on('load', function(){window.status = 'maploaded'});
Run Code Online (Sandbox Code Playgroud)
我对 wkhtmltopdf 的选择:
options = {
'dpi': 300,
'image-dpi': 400,
'zoom': 0.7,
'window-status': 'maploaded'
}
Run Code Online (Sandbox Code Playgroud)
我检查事件是否已触发,并且在触发后生成了 pdf,但地图未显示。
我应该怎么办?
我有一个mat-table我想自动适合列宽,任何人都会有最长的列内容.
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="email">
<mat-header-cell *matHeaderCellDef class="myHeader"> No. </mat-header-cell>
<mat-cell *matCellDef="let element" class="myCell"> {{element.email}} </mat-cell>
</ng-container>
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef class="myHeader"> Name </mat-header-cell>
<mat-cell *matCellDef="let element" class="myCell"> {{element.name}} </mat-cell>
</ng-container>
</mat-table>
Run Code Online (Sandbox Code Playgroud)
数据示例:
const DATA: Data[] = [
{email: 'mail1@mail.com', name: 'Long name for this person'},
{email: 'mail2@mail.com': 'name2',
{email: 'longmailaddres@longmailaddress.com: 'name3'}
];
Run Code Online (Sandbox Code Playgroud)
因此,宽度单元格足以用于"longmailaddress@longmailaddres.com"和"long person for this person".
我的选择不起作用,我尝试使用FxFlexFill和fxFlex unsucced这是我的css unsucced选项.
.myHeader, .myCell{
flex: 0 0 100px;
white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)
有人能帮助我吗?
我正在使用角垫桌。
我的问题是mat-cell的高度始终为14px(内部内容大小),但是我想修复mat-row的高度:
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="NAME">
<mat-header-cell fxFlex="100%" class="my-mat-header" *matHeaderCellDef>
{{'NAME' | translate}}
</mat-header-cell>
<mat-cell fxFlex="100%" class="my-mat-cell" *matCellDef="let element">
{{ element.name }}
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns" class="my-mat-header-row"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" class="my-mat-row"></mat-row>
</mat-table>
.my-mat-row {
min-height: 100%;
border-bottom: none;
padding: 5px 0;
}
.my-mat-cell {
color: black;
cursor: pointer;
min-height: 100%;
}
Run Code Online (Sandbox Code Playgroud)
垫行高度为50像素,而垫单元高度仅为14像素。
如何填充父高?
我正在使用routerLink返回我的页面.
目前的路线可以有3个级别:
myurl.com/parent
myurl.com/parent/child
myurl.com/parent/child/grandchild
Run Code Online (Sandbox Code Playgroud)
另外,我有一些不同的组件,因此它不会总是父组件,它可以是parent1,也可以是parent2,也可以是子组件和孙子组件,例如:
myurl.com/parent2/child1/grandchild2
Run Code Online (Sandbox Code Playgroud)
我想要的是总是去上一级,例如:
myurl.com/parent/child/grandchild -> myurl.com/parent/grandchild
Run Code Online (Sandbox Code Playgroud)
我做的是:
<button [routerLink]="['../'']">
back
</button>
Run Code Online (Sandbox Code Playgroud)
但它总是导航到"myurl.com"
我怎么解决呢?
正如一些用户建议的那样,我正在分享我的路由配置:
在app.routing.ts中:
const APP_ROUTES: Routes = [
{
path: '',
canActivate: [LoggedInGuard],
children: [
{path: '', redirectTo: '/mainPage', pathMatch: 'full'},
{path: 'parent', loadChildren: 'app/parent/parend.module#ParentModule'
]},
{path: '**', redirectTo: ''}
];
Run Code Online (Sandbox Code Playgroud)
在parent.routing.ts中:
const PARENT_ROUTES: Routes = [
{path: '', component: ParentComponent},
{path: ':id', component: ChildComponent},
];
Run Code Online (Sandbox Code Playgroud)
如果在浏览器中我写道:
myurl.com/parent -> it works
Run Code Online (Sandbox Code Playgroud)
但单击后退按钮失败
我有一个针对不同组件但有一些按钮的通用模板。因此,我创建一个通用组件并使用 ng-template 更改此按钮:
<component-common
[buttonTemplate]="buttonTemplate">
</component-common>
<ng-template #buttonTemplate let-element="element" let-method>
<button (click)="method">
element.name
</button>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
在组件common.component.ts中:
export class ComponentCommonComponent {
@Input() buttonTemplate: TemplateRef<any>;
constructor() { }
test() {
console.log("test called");
}
}
Run Code Online (Sandbox Code Playgroud)
并在html中:
<ng-template
*ngTemplateOutlet="buttonTemplate;context: {method: test(), element:element}">
</ng-template>
Run Code Online (Sandbox Code Playgroud)
我发现的问题是“test”一直被调用,而我只想在单击时调用它,我错过了什么?
I'm using promise.all in my resolver, it works, but now, I don't want an array of promises but an object, but I can't find how to do it.
This is my try:
resolve(route: ActivatedRouteSnapshot): Promise<any> {
return Promise.all([
this.service1.getAll(),
this.service2.getAll(),
this.service3.getAll()]
.map((result) => {
first: result[0],
second: result[1],
third: result[2]
})
)
}
Run Code Online (Sandbox Code Playgroud)
As you can see I want to convert the array into an object with key - value
how can I map the result to get an object …
我有一个正则表达式的麻烦.
我想替换myData=xxxx&xxxx可以改变的所有发生,但总是结束&,除了最后一次发生,它是什么时候myData=xxx.
var data = "the text myData=data1& and &myData=otherData& and end myData=endofstring"
data.replace(/myData=.*?&/g,'newData');
Run Code Online (Sandbox Code Playgroud)
它返回:
文本newData和&newData并结束myData = endofstring
这是正确的,但我怎么能检测到最后一个?
angular ×7
angular5 ×3
css ×2
angular-cdk ×1
css3 ×1
dictionary ×1
javascript ×1
leaflet ×1
list ×1
ng-template ×1
promise ×1
python ×1
python-3.x ×1
regex ×1
wkhtmltopdf ×1