我使用了以下代码。它可以正常工作,但我担心api为何会以“ data:”结果出现,如下所示
data: Array(2)
0: {id: 1, title: "Home", link: "/home"}
1: {id: 2, title: "About", link: "/about"}
我一直在学习本教程,它给出的输出类似
(2)[{..},{..}]
我不是同一个代码给我不同的输出。有人可以帮我吗?
谢谢。
export class InMemoryDataService implements InMemoryDbService {
constructor() { }
createDb() {
const menu = [
{ id: 1, title: 'Home', link: '/home' },
{ id: 2, title: 'About', link: '/about' }
];
return { menu };
}
导出类NavigationComponent实现OnInit {
menu: any;
database = 'menu';
constructor(private auth: AuthenticationService, private config: ConfigService) { }
ngOnInit() {
this.getMenu(this.database);
}
getMenu(database) {
this.config.getSettings(database).subscribe(
res => {
this.menu = res;
}
);
}
getSettings(database: string, id?: any): Observable<any[]> {
let uid = id || null;
let url: string;
if (uid !== null) {
url = `api/${database}/${id}`;
} else {
url = `api/${database}`;
}
return this.http.get<any>(url);
}