我在组件中使用角形材料,但看不到任何东西! 我把垫子选择,垫子桌子,日期选择器。 我只看到当我将鼠标悬停在上面时,corsur会发生变化,单击后会突然出现。 根本没有任何评论。 我添加了app.module,component.ts和component.html。
component.html:
<head >
<link href="https://fonts.googleapis.com/css?family=Amatic+SC:700&display=swap" rel="stylesheet">
</head>
<body class="main" style="direction: rtl">
<img class="logo" src="../assets/images/volta_logo.png">
<div class="select-space">
<mat-form-field>
<mat-label>work center</mat-label>
<mat-select>
<mat-option *ngFor="let workSpace of workSpaces" [value]="workSpace.value">
{{workSpace.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="choose-date">
<h5>תאריך:</h5>
<mat-form-field>
<mat-label>Choose a date</mat-label>
<input matInput [matDatepicker]="Frompicker">
<mat-datepicker-toggle matSuffix [for]="Frompicker"></mat-datepicker-toggle>
<mat-datepicker #Frompicker></mat-datepicker>
</mat-form-field>
<h5>date:</h5>
<mat-form-field>
<mat-label>Choose a date</mat-label>
<input matInput [matDatepicker]="Topicker">
<mat-datepicker-toggle matSuffix [for]="Topicker"></mat-datepicker-toggle>
<mat-datepicker #Topicker></mat-datepicker>
</mat-form-field>
</div>
<div>
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<!-- Weight Column -->
<ng-container matColumnDef="weight">
<th mat-header-cell *matHeaderCellDef> Weight </th>
<td mat-cell *matCellDef="let element"> {{element.weight}} </td>
</ng-container>
<!-- Symbol Column -->
<ng-container matColumnDef="symbol">
<th mat-header-cell *matHeaderCellDef> Symbol </th>
<td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>
</body>
component.ts:
import { Component } from '@angular/core';
import { MatFormFieldControl } from '@angular/material';
import { MatInputModule } from '@angular/material';
import { MatSelectModule } from '@angular/material';
interface workSpace {
value: string;
viewValue: string;
}
export interface PeriodicElement {
name: string;
position: number;
weight: number;
symbol: string;
}
export class TableBasicExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}
const ELEMENT_DATA: PeriodicElement[] = [
{position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
{position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
{position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
{position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
{position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
{position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
{position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
{position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
{position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
{position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
]
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
workSpaces: workSpace[] = [
{value: 'space-0', viewValue: 'space1'},
{value: 'space-1', viewValue: 'space2'},
{value: 'space-2', viewValue: 'space3'}
];
title = 'work';
}
app.module:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatFormFieldModule } from '@angular/material';
import { MatInputModule } from '@angular/material';
import { MatSelectModule } from '@angular/material';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material';
import { FormsModule } from '@angular/forms';
import { MatTableModule } from '@angular/material/table';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatDatepickerModule,
MatNativeDateModule,
FormsModule,
MatTableModule
],
exports: [ MatFormFieldModule, MatInputModule ],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
答案 0 :(得分:0)
删除此类:
export class TableBasicExample {
displayedColumns: string[] = ['position', 'name', 'weight', 'symbol'];
dataSource = ELEMENT_DATA;
}
,然后尝试在您的 AppComponent 类中移动声明。