小编Nik*_*hev的帖子

Angular 2,如何使用 queryParams 将数组传递到路由器

Angular 2 有没有办法获取这种 URL?

http://example.com/the-route?param[]=value1&param[]=value2&param[]=value3

我试图像应该那样使用queryParamsRouter但由于 queryParams 接受一个对象,所以我不能这样做:

this.router.navigate(['/the-route'], queryParams: { 'param[]': 'value1', 'param[]': 'value2', 'param[]': 'value3' });

因为,当然,我不能param[]在对象中多次使用相同的名称()

我正在努力解决如何做到这一点,但找不到方法

我看过这篇文章: Angular 2 pass array to router queryString。但没有正确答案

angular-routing angular

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

如何使用 Ruby 在 Amazon Athena 上执行查询?

如何将 Amazon Athena 与 Ruby 连接并通过 Amazon Athena 执行查询并获取结果。

我们无法找到任何 gem 或示例来帮助我们在 ruby​​ 中连接 Amazon Athena。

请提供任何参考,我们可以使用它来与 Amazon Athena 建立连接并在 Ruby 中构建自定义查询执行器。

只是为了澄清我的生产应用程序,因此将 SDK 从 Ruby 更改为 JRuby 对我来说不是一个合适的选择。

ruby amazon-web-services amazon-athena

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

如何在 POST 后刷新 angular2 中的 observable

我有一个显示信息的表,单击表行后,用户可以在完成请求后更新值,该表未使用新值更新,我必须按 F5 刷新视图。

如何在完成请求后强制执行新的 get 请求

这是相关的代码

我的服务

import { Injectable } from '@angular/core';

import { Http, Response } from '@angular/http';

import {Observable} from 'rxjs/Rx';

import { BehaviorSubject } from 'rxjs/BehaviorSubject';

// Import RxJs required methods
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

import { Device } from '../model/Device';

@Injectable()
export class DeviceService {

  devices$: BehaviorSubject<Device[]>;

  constructor(private http : Http) {
    this.initializeDevices();
  }

  initializeDevices() {
    var url = "./api/read/network/device";
    //var url = '../assets/data/devices.json';
    if (!this.devices$) {
      this.devices$ = <BehaviorSubject<Device[]>> new BehaviorSubject(new Array<Device>());
      this.http.get(url) …
Run Code Online (Sandbox Code Playgroud)

observable rxjs rxjs5 angular

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

使用 aws-sdk gem 检查 AWS S3 路径上是否存在文件

我正在尝试使用 ruby​​ on rails 应用程序中的 aws-sdk gem(版本 2)检查 AWS S3 上是否存在特定的 pdf 文件。

我已经建立了 AWS 连接,目前正在使用exists?方法:

puts @bucket.objects(prefix:"path/sample_100.pdf").exists?
Run Code Online (Sandbox Code Playgroud)

在运行上述语句时,我得到以下无方法错误:

undefined method 'exists?' for Aws::Resources::Collection
Run Code Online (Sandbox Code Playgroud)

检查了一些文件,但没有太大帮助。有没有其他方法可以实现相同的目标?

提前致谢

rubygems ruby-on-rails amazon-s3 amazon-web-services aws-sdk

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

如何使 ActiveRecord 查询按列唯一

我有一个Company模型有很多Disclosures. 将Disclosure有一个名为列titlepdfpdf_sha256

class Company < ActiveRecord::Base
  has_many :disclosures
end

class Disclosure < ActiveRecord::Base
  belongs_to :company
end
Run Code Online (Sandbox Code Playgroud)

我想让它独特的pdf_sha256,如果pdf_sha256就是nil应该被视为是唯一的。

如果是Array,我会这样写。

companies_with_sha256 = company.disclosures.where.not(pdf_sha256: nil).group_by(&:pdf_sha256).map do |key,values|
  values.max_by{|v| v.title.length}
end
companies_without_sha256 = company.disclosures.where(pdf_sha256: nil)
companies = companies_with_sha256 + companeis_without_sha256
Run Code Online (Sandbox Code Playgroud)

如何使用 ActiveRecord 查询获得相同的结果?

postgresql activerecord ruby-on-rails

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

Angular NGRX/Observables 和 Reactive Forms

目前我有一个项目使用 NGRX 作为其存储和反应形式。

在我的应用程序中,我想将我状态中的活动项映射到反应形式。所以在我的组件中,我有类似的东西:

export class MyComponent {

    active$: Observable<any>;

    form = this.fb.group({
        name: ['', [Validators.required]],
        description: ['', Validators.maxLength(256)]
    });

    constructor(private fb: FormBuilder, private store: Store<any>) {
        this.active$ = store.select(store => store.items);
    }
    
}
Run Code Online (Sandbox Code Playgroud)

为了避免订阅商店并选择我的项目,我创建了一个指令来将我的可观察对象绑定到我的表单:

import { Directive, Input } from '@angular/core';
import { FormGroupDirective } from '@angular/forms';

@Directive({
    selector: '[connectForm]'
})
export class ConnectFormDirective {

    @Input('connectForm')
    set data(val: any) {
        if (val) {
            this.formGroupDirective.form.patchValue(val);
            this.formGroupDirective.form.markAsPristine();
        }
    }

    constructor(private formGroupDirective: FormGroupDirective) { }

}
Run Code Online (Sandbox Code Playgroud)

现在在我的表单中,我只是像这样绑定它:

<form [formGroup]="form" novalidate (ngSubmit)="onSubmit()" [connectForm]="active$ …
Run Code Online (Sandbox Code Playgroud)

rxjs ngrx angular angular-reactive-forms

5
推荐指数
2
解决办法
4024
查看次数

对 rxjs 订阅进行反跳和缓冲

我有一个消息队列处理器,可以将消息提供给服务......

q.on("message", (m) => {
  service.create(m)
    .then(() => m.ack())
    .catch(() => n.nack())
})
Run Code Online (Sandbox Code Playgroud)

该服务使用 RxJS Observable 并订阅debounceTime()这些请求。

class Service {
  constructor() {
    this.subject = new Subject()
    this.subject.debounceTime(1000)
      .subscribe(({ req, resolve, reject }) =>
        someOtherService.doWork(req)
          .then(() => resolve())
          .catch(() => reject())
      )
  }

  create(req) {
    return new Promise((resolve, reject) =>
      this.subject.next({
        req,
        resolve,
        reject
      })
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是只有去抖请求才会得到 ackd/nackd。如何确保订阅也解决/拒绝其他请求? bufferTime()让我到达那里的一部分,但它不会重置每次调用的超时持续时间next()

rxjs rxjs5

5
推荐指数
2
解决办法
3212
查看次数

使用 Nestjs 进行超级测试 e2e:请求不是函数

我尝试为我的简单 NestJS 后端服务引入 e2e 测试。我提供一个自定义 userService 和一个用 sinon 模拟的自定义 UserRepository。

这是我的user.e2e-spec.ts文件:

import * as request from 'supertest';
import * as sinon from 'sinon';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { UserService } from '../../src/user/user.service';
import { getRepositoryToken } from '@nestjs/typeorm';
import { User } from '../../src/user/user.entity';
import { TestUtil } from '../../src/utils/TestUtil';
import { createFakeUser } from '../../src/user/test/userTestUtil';

let sandbox: sinon.SinonSandbox;
let testUtil;

describe('User', () => {
    let app: INestApplication;
    const …
Run Code Online (Sandbox Code Playgroud)

node.js supertest e2e-testing nestjs

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

如何使用来自其他 Angular 组件的`templateref`?

如何templateRef从其他组件模板文件中使用?

我有BatmanComponentSpidermanComponent还有一个JokerComponent。其中一些具有类似的功能,因此我决定创建一个HumanComponent, 并将所有可重用的 HTML 代码放在该文件中,如下所示:

注意:HumanComponent永远不会使用,它只是一个包含所有默认模板的文件。

<!-- human.component.ts -->
<ng-template #eye>
    Eyes: {{ size }}
</ng-template>
<ng-template #body>
    Body: bust {{ x[0] }}, waist {{ x[1] }}, hip {{ x[2] }} 
</ng-template>
Run Code Online (Sandbox Code Playgroud)

我可以知道如何注入这些模板(来自human.component.ts)并在batman.component.ts.... 中使用它吗?

我知道我可以这样做:(仅模板代码被复制粘贴到蝙蝠侠、蜘蛛侠和小丑HTML 文件中时)

<!-- batman.component.ts -->
<ng-container *ngTemplateOutlet="eye; context: contextObj"></ng-container>

<ng-template #eye> ... </ng-template> <!-- need to copy/paste here, and use it locally -->
Run Code Online (Sandbox Code Playgroud)

我可以知道如何导出 templateRef …

angular

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

Angular 8:装饰器不支持函数表达式

我在尝试在 Angular 8 中构建 prod 时遇到问题。错误是

ERROR in Error during template compile of 'AppModule'
  Function expressions are not supported in decorators in 'SocketLibModule'
    'SocketLibModule' references 'initializeApp'
      'initializeApp' contains the error at ../socket-lib/src/lib/socket-lib.module.ts(9,12)
        Consider changing the function expression into an exported function.
Run Code Online (Sandbox Code Playgroud)

什么指向我的库

export const SOCKET_CONFIG = new InjectionToken<SocketConfig>('SOCKET_CONFIG');

export function initializeApp(socketConfig: SocketConfig) {
  return (uriConfig: any) => {
    return () => uriConfig.load(socketConfig);
  };
}

@NgModule()
export class SocketLibModule {
  public static forRoot(socketConfig: SocketConfig): ModuleWithProviders {
    return {
      ngModule: SocketLibModule,
      providers: …
Run Code Online (Sandbox Code Playgroud)

typescript angular

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