Angular 6材料数据表格与单选按钮
创始人
2024-10-16 06:30:27
0

以下是一个使用Angular 6的材料数据表格和单选按钮的解决方案的示例代码:

  1. 创建一个名为app.component.html的HTML文件:

Angular Material Data Table with Radio Buttons

Position {{element.position}} Name {{element.name}} Weight {{element.weight}}
  1. 创建一个名为app.component.ts的TypeScript文件:
import { Component } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';

export interface Element {
  position: number;
  name: string;
  weight: number;
}

const ELEMENT_DATA: Element[] = [
  {position: 1, name: 'Hydrogen', weight: 1.0079},
  {position: 2, name: 'Helium', weight: 4.0026},
  {position: 3, name: 'Lithium', weight: 6.941},
  {position: 4, name: 'Beryllium', weight: 9.0122},
  {position: 5, name: 'Boron', weight: 10.811},
];

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  displayedColumns: string[] = ['select', 'position', 'name', 'weight'];
  dataSource = new MatTableDataSource(ELEMENT_DATA);
  selectedRow: Element;

  selectRow(row: Element) {
    this.selectedRow = row;
  }
}
  1. app.module.ts中导入Angular Material模块:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MatTableModule } from '@angular/material/table';
import { MatRadioModule } from '@angular/material/radio';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    MatTableModule,
    MatRadioModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  1. 运行应用程序:

确保已安装Angular CLI,并在终端中运行以下命令:

ng serve

打开浏览器并访问http://localhost:4200,你将看到一个带有单选按钮的材料数据表格。当你选择一行时,该行将被高亮显示。

相关内容

热门资讯

攻略讲解!pokemmo手机版... 攻略讲解!pokemmo手机版脚本,hhpoker透视脚本视频,解密教程(有挂软件)是一款可以让一直...
分享实测!wepoker有什么... 分享实测!wepoker有什么规律,hardrock作弊,可靠教程(有挂软件)是由北京得wepoke...
交流学习经验!wepoker底... 交流学习经验!wepoker底牌透视,wepoker网页版透视方法,存在挂教程(有挂教程)关于wep...
发现玩家!德普之星辅助器,we... 1、发现玩家!德普之星辅助器,wepoker手机插件,曝光教程(有挂技巧);详细教程。2、德普之星辅...
一起来讨论!德州局透视脚本免费... 一起来讨论!德州局透视脚本免费版下载手机版,wepoker私人局俱乐部,AA德州教程(有挂技巧);致...
技术分享!we poker辅助... 技术分享!we poker辅助器v3.3,aapoker ai插件,详细教程(有挂攻略);亲真的是有...
实测必看!wepoker智能辅... 实测必看!wepoker智能辅助插件,wepoker轻量版透视系统,我来教教你(有挂神器);原来确实...
玩家必看!wepoker私人局... 玩家必看!wepoker私人局外卦,wepoker怎么设置透视,可靠技巧(有挂攻略)是一款可以让一直...
实测发现!wepoker免费透... 实测发现!wepoker免费透视,pokemomo辅助软件,攻略教程(有挂软件)1、点击下载安装,微...
让我来分享经验!wepoker... 让我来分享经验!wepoker智能辅助插件,wepoker辅助透视,曝光教程(有挂方法);《WPK辅...