小编Jij*_*bin的帖子

角度路由不显示内容

我想以这样的方式实现路由:如果您单击下拉列表,它就会转到该特定页面。但我希望在路由到其他组件时保留标头。它会转到特定的 url,但不显示内容。我尝试过子路由,但它似乎不起作用。

上图是下拉菜单的样子。它有以下网址

本地主机:4200/正文

当我单击用户管理时,我希望它转到

本地主机:4200/body/用户

虽然它转到特定的网址,但它没有显示下面的任何内容,如图所示。

这些是我的代码(app.routing.ts 和 .html)

javascript angular-routing angular angular6

2
推荐指数
1
解决办法
6375
查看次数

在收到角度握手响应之前连接已关闭

我正在尝试进行套接字连接。但我收到上述错误。我正在尝试使用不同的端点来实现https://tutorialedge.net/typescript/angular/angular-websockets-tutorial/ 。

套接字服务.ts

import { Injectable } from '@angular/core';
import * as Rx from 'rxjs/Rx';

@Injectable({
providedIn: 'root'
})
export class SocketService {

constructor() { }

private subject: Rx.Subject<MessageEvent>;

public connect(url): Rx.Subject<MessageEvent> {
if (!this.subject) {
  this.subject = this.create(url);
  console.log("Successfully connected: " + url);
  } 
  return this.subject;
  }

  private create(url): Rx.Subject<MessageEvent> {
  let ws = new WebSocket(url);

  let observable = Rx.Observable.create(
  (obs: Rx.Observer<MessageEvent>) => {
    ws.onmessage = obs.next.bind(obs);
    ws.onerror = obs.error.bind(obs);
    ws.onclose = obs.complete.bind(obs);
    return ws.close.bind(ws);
   })
 let observer …
Run Code Online (Sandbox Code Playgroud)

websocket typescript angular angular6

2
推荐指数
1
解决办法
3011
查看次数

将json数据转换为component.ts中的对象

我有json数据,我想将其转换为对象格式以进行创建操作.

JSON

[
{
    "user": {
        "id": 83,
        "username": "das",
        "first_name": "dsafha",
        "last_name": "dfksdfk",
        "email": "sasda@gmail.com",
        "is_active": true,
        "is_superuser": false
    },
    "role": "testBu"
},
{
    "user": {
        "id": 84,
        "username": "sadfds",
        "first_name": "dshhgds",
        "last_name": "fsdjsl",
        "email": "fdjgd@gmail.com",
        "is_active": true,
        "is_superuser": false
    },
    "role": "testeditrole"
},
{
    "user": {
        "id": 86,
        "username": "fs",
        "first_name": "efhks",
        "last_name": "sofdh",
        "email": "fdshk@gmail.com",
        "is_active": true,
        "is_superuser": false
    },
    "role": "testeditrole"
},
{
    "user": {
        "id": 87,
        "username": "xz",
        "first_name": "vj",
        "last_name": "vkfd",
        "email": "sdsl@gmail.com",
        "is_active": …
Run Code Online (Sandbox Code Playgroud)

angular angular5 angular6 angular6-json-schema-form

0
推荐指数
1
解决办法
324
查看次数