小编Ash*_*oyi的帖子

什么是Angular Material 2组件中的`cdk`

在角度材质源中的多个位置,有元素/ css类cdk作为其前缀.

有谁知道cdk角度材料上下文中的缩写?

angular-material2 angular-cdk

104
推荐指数
3
解决办法
3万
查看次数

在变量或类名前面的_(下划线)中是否有标准?

我见过一些程序员_在类名前面使用(下划线),还有一些程序员使用它来表示局部变量.

Java标准是否要求/建议在私有实例变量或类名前面使用_(下划线)?

java coding-style

22
推荐指数
4
解决办法
3万
查看次数

如何使用angular2 http API跟踪上传/下载进度

有许多adhoc库支持angular2的上传/下载进度,我不知道如何使用native angular2 http api在上传/下载时显示进度.

我想使用原生http api的原因是因为我想利用它

  1. 本机http api周围的http拦截器(http API包装器),用于验证,缓存和丰富正在发送的http请求,例如this&this
  2. 除了angular之外,http api比任何adhoc API都强大得多

一篇关于如何使用angular的http api进行上传/下载的好文章

但该文章提到,没有本土方式来支持进步.

有没有人尝试使用http api来显示进度?

如果没有,你知道角度回购中的问题吗?

http interceptor angular2-http angular

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

动态创建具有ng-content的angular2组件

我想设置<ng-content>动态实例化组件的主体ComponentFactoryResolver.

我看到我可以使用输入和输出访问ComponentRef,但不能设置<ng-content>.

请注意<ng-content>我计划设置可以包含简单文本/可以跨越动态创建的组件

@Component({
    selector: 'app-component-to-project',
    template: `<ng-content></ng-content>`
})
export class ComponentToProject implements AfterContentInit {

    ngAfterContentInit() {
        // We will do something important with content here
    }

}


@Directive({
    selector: 'appProjectionMarker'
})
export class ProjectionMarkerDirective implements OnInit {

    constructor(private viewContainerRef: ViewContainerRef, private componentFactoryResolver: ComponentFactoryResolver) {
    }

    ngOnInit() {
        const componentFactory: ComponentFactory<ComponentToProject> = this.componentFactoryResolver.resolveComponentFactory(ComponentToProject);
        const componentRef: ComponentRef<ComponentToProject> = this.viewContainerRef.createComponent(componentFactory);
        // Question: How to set content before the child's afterContentInit is invoked …
Run Code Online (Sandbox Code Playgroud)

angular-components angular

12
推荐指数
1
解决办法
6924
查看次数

访问模板元素内的模板引用

我正在使用一个库,希望我指定一个指令的主体作为template元素的子元素

<template customDirective>
   <custom-element #lookup></custom-element>
</template>
Run Code Online (Sandbox Code Playgroud)

有没有办法访问custom-element#lookup我的组件内部.

例如,

@Component({
  selector: 'app-test',
  template: `
    <template customDirective>
       <custom-element #lookup></custom-element>
    </template>
  `
})
export class TestComponent {
  @ViewChild('lookup') viewChildRef;
  @ContentChild('lookup') contentChildRef;

  constructor() {
  }

  ngAfterContentInit(): void {
     console.log(this.viewChildRef); // <-- undefined
     console.log(this.contentChildRef); // <-- undefined
  }
}
Run Code Online (Sandbox Code Playgroud)

我遇到undefined了两种情况.

angular2-template angular

10
推荐指数
1
解决办法
5408
查看次数

Angular2传递函数作为组件输入不起作用

我有一个将函数作为输入的组件.我从父母传递了这个功能.

虽然调用了该函数,但该函数无法访问声明此函数的实例的依赖项.

这是组件

@Component({
  selector: 'custom-element',
  template: `
    {{val}}
  `
})
export class CustomElement {
  @Input() valFn: () => string;

  get val(): string {
    return this.valFn();
  }
}
Run Code Online (Sandbox Code Playgroud)

以下是组件的使用方法

@Injectable()
export class CustomService {
  getVal(): string {
    return 'Hello world';
  }
}

@Component({
  selector: 'my-app',
  template: `
   <custom-element [valFn]="customVal"></custom-element>
  `,
})
export class App {
  constructor(private service: CustomService) {
  }
  customVal(): string {
    return this.service.getVal();
  }
}
Run Code Online (Sandbox Code Playgroud)

当我运行这个应用程序时,我在控制台中收到错误说 Cannot read property 'getVal' of undefined

这是一个问题的掠夺者.

https://plnkr.co/edit/oQ229rXqOU9Zu1wQx18b?p=preview

angular2-template angular2-di angular

10
推荐指数
1
解决办法
1万
查看次数

使用spring webclient对http请求进行可读的调试日志记录

我正在使用Spring反应式WebClient向http服务器发送请求.为了查看正在发送的基础请求和响应,我启用了reactor.ipc.netty包的调试日志记录.

可以正常查看传出请求的标头.

我通过http发送和接收纯文本,日志包含以下格式的请求和响应(是十六进制吗?)

我不确定如何以易于理解的方式查看记录的数据.更好的是以可理解的方式记录请求和响应

这是记录数据的片段

         +-------------------------------------------------+
         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |
+--------+-------------------------------------------------+----------------+
|00000000| 47 45 54 20 2f 53 65 61 72 63 68 5f 47 43 2e 61 |GET /Search_GC.a|
|00000010| 73 70 78 20 48 54 54 50 2f 31 2e 31 0d 0a 75 73 |spx HTTP/1.1..us|
|00000020| 65 72 2d 61 67 65 6e 74 3a 20 52 65 61 63 …
Run Code Online (Sandbox Code Playgroud)

spring webclient project-reactor reactor-netty spring-webflux

6
推荐指数
2
解决办法
2572
查看次数

当一般意义上它们不是适配器时,为什么我们在Spring Java Configuration中有*Adapter类

在使用Spring的Java配置时,您必须看到类似WebMvcConfigurerAdapterHandlerInterceptorAdapter的类,这些类实现了单个接口,并且它们遵循应该为真实适配器保留的*Adpater约定(此特定类不会将调用从一个接口转换为不同的界面).

有没有人知道我的理解是否有任何问题/他们使用错误的惯例?

spring design-patterns spring-mvc naming-conventions spring-java-config

5
推荐指数
1
解决办法
1083
查看次数

CPU 是否会在因 IO 读/写而阻塞的 java 线程上浪费时间?

如果一个线程在向 IO 写入数据时被阻塞,CPU 是否需要给该线程任何时间,直到该 IO 操作完成?

如果是这样,为什么CPU要放弃呢?

如果不是,除了“每个线程堆栈”之外,是否还有其他因素使得“每个线程请求”在重负载下的性能不如“共享线程的非阻塞 IO”?

PS:我已经阅读了很多关于这个主题的问题,但我找不到解决这个特定方面的答案

java io multithreading nonblocking

5
推荐指数
1
解决办法
1420
查看次数

为什么 spring-websocket 中的 STOMP 功能依赖于 Spring MVC?

目前,我正在尝试使用 webflux 将 STOMP 与 websockets 一起使用。为了向 STOMP 主题发送消息,我需要使用SimpMessagingTemplate,这是我添加时由 spring boot 自动配置提供的@EnableWebSocketMessageBroker

但问题是,@EnableWebSocketMessageBroker间接地希望我spring-mvc在类路径中有库

@EnableWebSocketMessageBroker @ImportsDelegatingWebSocketMessageBrokerConfiguration扩展WebSocketMessageBrokerConfigurationSupport&WebSocketMessageBrokerConfigurationSupport#stompWebSocketHandlerMapping方法期望HandlerMapping返回该类

我的问题是

  1. 如何在没有 webmvc 的情况下将 STOMP 与 webflux 集成
  2. 为什么自动配置迫使我们在类路径中有 mvc(并且可能与 webflux 冲突)

stomp spring-messaging spring-websocket spring-webflux

5
推荐指数
1
解决办法
1864
查看次数