【问题标题】:How to use json in menu Angular5 NODEJS如何在菜单Angular5 NODEJS中使用json
【发布时间】:2018-09-16 18:35:02
【问题描述】:

嗯,我一直在阅读,但我找不到解决方案。我从这个项目开始。我想知道如何使用像 https://api.myjson.com/bins/1axhir 这样的带有 GET 方法的服务并在我的菜单中使用它。这就是我的代码的编写方式。我使用的是 NGX-ADMIN 模板,但他们没有任何文档。

page.components.ts

import { Component } from '@angular/core';
import { MENU_ITEMS } from './pages-menu';

@Component({
  selector: 'ngx-pages',
  template: `
    <ngx-sample-layout>
      <nb-menu [items]="menu"></nb-menu>
      <router-outlet></router-outlet>
    </ngx-sample-layout>
  `,
})
export class PagesComponent {

  menu = MENU_ITEMS;
}

pages-menu.ts

import { NbMenuItem } from '@nebular/theme';
export const MENU_ITEMS: NbMenuItem[] = [
  {
    title: 'Dashboard',
    icon: 'nb-home',
    link: '/pages/dashboard',
    home: true,
  },
  {
    title: 'CONFIGURACIONES',
    group: true,
  },
  {
    title: 'Usuarios',
    icon: 'nb-keypad',
    link: '/pages/ui-features',
    children: [
      {
        title: 'Buttons',
        link: '/pages/ui-features/buttons',
      },
    ],
  },
];

我想使用 Web 服务,例如 https://api.myjson.com/bins/1axhir,而不是常量数组,请帮帮我。 TY

【问题讨论】:

标签: json node.js angular rest web-services


【解决方案1】:

Angular 仅用于前端,要制作 API,您需要使用 Node.js 或任何其他后端框架。

如果你愿意,我可以给你同样的 node.js 代码。

同样为了将 API 集成到 Angular 应用程序中,您需要使用可观察对象和订阅者

【讨论】:

  • 是的,我使用 Node.js 作为后端。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-18
  • 1970-01-01
相关资源
最近更新 更多