【发布时间】:2025-11-30 13:50:01
【问题描述】:
我正在开发一个基于 Web 的应用程序。我使用 Angular 和 Web API 开发应用程序,DBMS:SQL Server Management Studio 17。
我想在 Angular Material 数据表中填充存储在我的数据库中的数据。
这是我的 customer-req-table-datasource.ts。
import { DataSource } from '@angular/cdk/collections';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { map } from 'rxjs/operators';
import { Observable, of as observableOf, merge } from 'rxjs';
// TODO: Replace this with your own data model type
export interface CustomerReqTableItem {
name: string;
id: number;
}
// TODO: replace this with real data from your application
const EXAMPLE_DATA: CustomerReqTableItem[] = [
{id: 1, name: 'Hydrogen'},
{id: 2, name: 'Helium'},
{id: 3, name: 'Lithium'},
{id: 4, name: 'Beryllium'},
{id: 5, name: 'Boron'},
{id: 6, name: 'Carbon'},
{id: 7, name: 'Nitrogen'},
{id: 8, name: 'Oxygen'},
{id: 9, name: 'Fluorine'},
{id: 10, name: 'Neon'},
{id: 11, name: 'Sodium'},
{id: 12, name: 'Magnesium'},
{id: 13, name: 'Aluminum'},
{id: 14, name: 'Silicon'},
{id: 15, name: 'Phosphorus'},
{id: 16, name: 'Sulfur'},
{id: 17, name: 'Chlorine'},
{id: 18, name: 'Argon'},
{id: 19, name: 'Potassium'},
{id: 20, name: 'Calcium'},
];
这是我的 customer.service.ts 文件
import { HttpClient } from '@angular/common/http';
import { Employee } from './employee.model';
import { Customer } from './customer.model';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class CustomerService {
formData: Customer;
list: Customer[];
readonly rootURL = 'https://localhost:44300/api';
constructor(private http: HttpClient) { }
postCustomer(formData: Customer) {
return this.http.post(this.rootURL + '/Customer', formData);
}
refreshList() {
this.http.get(this.rootURL + '/Customer').toPromise().then(res => this.list = res as Customer[]);
}
putCustomer(formData: Customer) {
return this.http.put(this.rootURL + '/Customer/' + formData.CustomerID, formData);
}
deleteCustomer(id: number) {
return this.http.delete(this.rootURL + '/Customer/' + id);
}
}
问题:如何设置list[]数组(在service.ts文件中)数据并填充角度数据表?
但是,我的最终目标是获取数据库中的数据并使用角度数据表显示这些数据。
【问题讨论】:
-
FYI,"SQL Server Management Studio" 不是数据库引擎版本,它只是一个客户端接口。要获取数据库版本,请尝试
select @@version
标签: sql-server angular typescript angular-material asp.net-web-api2