Angular 6 - 路由未发生 - Mat-table 行
创始人
2024-10-16 01:30:37
0

要解决“Angular 6 - 路由未发生 - Mat-table 行”问题,需要检查以下几个方面:

  1. 确保路由器正确配置并且导航到正确的组件。检查app.module.ts文件中的路由配置,确保路由路径正确,并且路由导航到包含Mat-table行的组件。

  2. 确保在路由导航后正确加载Mat-table数据。在组件的ngOnInit()函数中,确保通过适当的方法加载Mat-table的数据。这可以是从服务中获取数据,或者从本地变量中加载。

下面是一个示例代码,演示如何在Angular 6中使用Mat-table和路由导航:

  1. 在app.module.ts文件中配置路由:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { MyComponent } from './my-component/my-component.component';

const routes: Routes = [
  { path: '', redirectTo: '/my-component', pathMatch: 'full' },
  { path: 'my-component', component: MyComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
  1. 在my-component.component.ts文件中加载Mat-table数据:
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnInit {
  dataSource: any[];

  constructor(private dataService: DataService) { }

  ngOnInit() {
    this.dataService.getData().subscribe(data => {
      this.dataSource = data;
    });
  }
}
  1. 在my-component.component.html文件中使用Mat-table显示数据:

    
    
Name {{element.name}} Age {{element.age}}
  1. 创建一个data.service.ts文件来获取数据:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class DataService {
  constructor(private http: HttpClient) { }

  getData() {
    return this.http.get('https://api.example.com/data');
  }
}

确保将上述代码与您的项目进行适当的调整,并根据您的需求进行修改,以使其适应您的项目。

相关内容

热门资讯

透视关于!wepoker透视有... 透视关于!wepoker透视有用吗(透视)wpk可以透视吗,教程窍门(有挂教学)-哔哩哔哩1、完成w...
aapoker真的假的!wep... aapoker真的假的!wepoker透视脚本下载(透视)挂-竟然详细存在有挂wepoker透视脚本...
透视关于!xpoker透视辅助... 透视关于!xpoker透视辅助(透视)约局吧德州透视,教程教程书(有挂规律)-哔哩哔哩约局吧德州透视...
hhpoker软件靠谱吗!we... hhpoker软件靠谱吗!wepoker私人局开挂视频(透视)教程-一直推荐是真的挂亲,关键说明,w...
透视关于!aapoker辅助工... 透视关于!aapoker辅助工具安全吗(透视)werplan辅助软件,教程绝活儿(确实有挂)-哔哩哔...
德普之星辅助工具如何设置!we... 德普之星辅助工具如何设置!wepoker轻量版书签(透视)工具-一直教你真的有挂德普之星辅助工具如何...
wepoker怎么拿到好牌!w... wepoker怎么拿到好牌!wepokerplus透视脚本免费(透视)插件-确实解谜有挂1、超多福利...
透视专业!wepoker好友局... 透视专业!wepoker好友局透视(透视)wepoker透视最简单三个步骤,教程项目(有挂技术)-哔...
德普之星app安卓版破解版!w... 德普之星app安卓版破解版!we poker游戏下(透视)插件-竟然有挂有挂1、玩家可以在德普之星a...
透视关于!德州局透视(透视)约... 透视关于!德州局透视(透视)约局吧辅助器,教程大纲(有挂分享)-哔哩哔哩1、下载好约局吧辅助器脚本下...