小编Bre*_*ett的帖子

等待两个 Observable 完成

我想在两个 Observable 返回值后调用一个方法。我做了一些搜索,这似乎forkJoin是我想要的,但我无法让它工作。我知道这两个 Observable 都在返回值,因为我在组件的其他地方单独使用每个数据,所以很明显我做错了其他事情。

这是我尝试过的。我正在使用 rxjs v6.4。

forkJoin(
  this.store.pipe(select(fromStore.getAppointmentsLoading)),
  this.clientStore.pipe(select(fromClientStore.getClientsLoading)),
).subscribe(
  ([res1, res2]) => {
    console.log('res1', res1);
    console.log('res2', res2);
  },
  err => console.error(err),
);
Run Code Online (Sandbox Code Playgroud)

没有任何内容记录到控制台,我也没有收到任何错误。同样,我传入的 Observable 肯定是返回值。

我做错了什么,还是我完全使用错误的方法forkJoin?

fork-join rxjs ngrx angular

4
推荐指数
1
解决办法
3343
查看次数

如何使用1000个随机生成的int创建数组?

我应该创建一个1000个int的数组并编写一个方法来查找最大的int然后打印它.这是我到目前为止:

public static int findLargest(int[] numbers){  
    int largest = numbers[0];  
    for(int i = 1; i < numbers.length; i++){  
        if(numbers[i] > largest){  
            largest = numbers[i];  
        }  
    }  
    return largest;
}
Run Code Online (Sandbox Code Playgroud)

首先,如何创建一个包含1000个随机生成的int的数组?我试过int[] array = new (int)(Math.random());但我不知道如何让它做1000个随机数.其次,如何打印结果?在此先感谢您的帮助.

java arrays int

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

包括"?" 和Angular 2中的URL中的"="

在Angular 2中,如何在URL中包含问号和等号?我尝试了以下两种方式:

在html中:

routerLink="./Example?tour=true"
Run Code Online (Sandbox Code Playgroud)

在TypeScript中:

this.router.navigate(['/Example?tour=true']);
Run Code Online (Sandbox Code Playgroud)

这两个例子都导致: /Example%3Ftour%3Dtrue

如何让我的URL工作并显示我想要的方式?

angular2-routing angular

3
推荐指数
1
解决办法
697
查看次数

Angular OnPush 不更新模板

我有两个组件,它们都设置为OnPush. 父组件集accountLoading为true,一旦getAccount()被调用,然后设置accountLoading为false,一旦完成呼叫。正如预期的那样,控制台输出:

this.accountLoading 真

其次是:

this.accountLoading 假

然而模板没有更新,并且一直认为这accountLoading是真的。当值发生变化时,如何让模板按预期更新?我想将更改检测保留为 OnPush。

父组件:

打字稿:

public accountLoading: boolean;
...

getAccount() {
  this.accountLoading = true;
    this.authStore
        .pipe(select(fromAuthStore.getAccountData))
        .subscribe(account => {
          if (account) {
            this.accountLoading = false;
          }
          console.log('this.accountLoading', this.accountLoading);
        });

  // Loading account if it hasn't yet been loaded
  this.authService.getAccount();
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<child-component
  [accountLoading]="accountLoading">
</child-component>
Run Code Online (Sandbox Code Playgroud)

子组件:

打字稿:

@Input() accountLoading: boolean;
...
Run Code Online (Sandbox Code Playgroud)

HTML:

<p *ngIf="accountLoading">
  Loading...
</p>
Run Code Online (Sandbox Code Playgroud)

angular angular-changedetection

3
推荐指数
1
解决办法
1739
查看次数

使用 Twilio 和 Google Cloud Functions 时请求的内容类型不正确

我正在关注有关如何使用我的应用程序回复短信的 Twilio 教程: https://www.twilio.com/docs/sms/tutorials/how-to-receive-and-reply-node-js

本教程假设您使用的是 Express,但我使用 Cloud Function 执行此操作,因此我的代码看起来有点不同:

exports.sms = functions.https.onCall((req: any, res: any) => {
    const twiml = new MessagingResponse();

    if (req.body.Body === 'hello') {
        twiml.message('Hi!');
    } else if (req.body.Body === 'bye') {
        twiml.message('Goodbye');
    } else {
        twiml.message(
            'No Body param match, Twilio sends this in the request to your server.',
        );
    }

    res.writeHead(200, { 'Content-Type': 'text/xml' });
    res.end(twiml.toString());
});
Run Code Online (Sandbox Code Playgroud)

当我向 Twilio # 发送短信时,它会到达该端点,但出现以下错误:

请求的内容类型不正确。应用程序/x-www-form-urlencoded

我该如何解决这个问题?

twilio firebase google-cloud-functions twilio-api

3
推荐指数
1
解决办法
1361
查看次数

Perl - 简单if语句不起作用

我正在尝试编写一个循环来确定用户输入是否与字符串$ rev匹配.无论我为$ seq键入什么,它都会返回它不匹配,即使它实际上是.我究竟做错了什么?谢谢你的帮助.

$seq = <>;
$rev = "string";
if ($seq eq $rev){
    printf("The two strings match.\n");
}
else {
    printf("The two strings do NOT match.\n");
}
Run Code Online (Sandbox Code Playgroud)

perl stdin

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

FileInputStream错误Java

我试图用Java读取一个名为"KFormLList.txt"的文件.它与此程序一起保存在默认包中,但是当我尝试运行它时,我收到以下错误消息:"错误:KFormLList.txt(系统找不到指定的文件)"

我究竟做错了什么?谢谢你的帮助.

import java.io.*;

public class VLOCGenerater {

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        //Read the text file "KFormLList.txt"
        FileInputStream fis = new FileInputStream("KFormLList.txt");

        DataInputStream dis = new DataInputStream(fis);
        BufferedReader br = new BufferedReader(new InputStreamReader(dis));
        String strLine;
        int V = 0;
        int LOC = 0;

        while((strLine = br.readLine())!= null ){
            if (strLine.trim().length() != 0){
                System.out.println(strLine);
                V++;
                }
            else {
                LOC++;
            }
        }
        System.out.println("V = " + V);
        System.out.println("LOC = " + LOC);
        dis.close(); …
Run Code Online (Sandbox Code Playgroud)

java fileinputstream

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

为 HTML 文件配置 Prettier

我查看了 Prettier 的文档并进行了大量搜索,但无法弄清楚如何按照我想要的方式配置 Angular html 文件。如果元素不超过一行的最大字符数,我希望元素位于一行上,但如果确实超过最大值,那么我只需要每行一个属性,如下所示。

所需的格式:

<app-example-component [attribute1]="attribute1"></app-example-component>

<app-example-component
  [attribute1]="attribute1"
  [attribute2]="attribute2"
  [attribute3]="attribute3"
  [attribute4]="attribute4"
></app-example-component>
Run Code Online (Sandbox Code Playgroud)

这是我目前得到的,我发现很难阅读:

<app-example-component [attribute1]="attribute1" [attribute2]="attribute2"
  [attribute3]="attribute3" [attribute4]="attribute4"
  [attribute3]="attribute3" [attribute4]="attribute4"
  [attribute3]="attribute3"></app-example-component>
Run Code Online (Sandbox Code Playgroud)

我正在使用 VS Code,并且最近将我的 Angular 项目转换为使用 ESLint 而不是 TSLint,但在此之前我没有使用 Prettier,所以我不知道该转换是否会导致问题。

这是我的.eslintrc.json文件。也许这对我来说破坏了 Prettier?

{
  "root": true,
  "ignorePatterns": [
    "projects/**/*"
  ],
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "parserOptions": {
        "project": [
          "tsconfig.json",
          "e2e/tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": [
        "plugin:@angular-eslint/ng-cli-compat",
        "plugin:@angular-eslint/ng-cli-compat--formatting-add-on",
        "plugin:@angular-eslint/template/process-inline-templates"
      ],
      "rules": {
        "@typescript-eslint/consistent-type-definitions": "error",
        "@typescript-eslint/dot-notation": "off",
        "@typescript-eslint/explicit-member-accessibility": [
          "off",
          {
            "accessibility": "explicit"
          } …
Run Code Online (Sandbox Code Playgroud)

eslint visual-studio-code angular prettier

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

使用java计算float数组中递增数字的总和

我应该编写一个Java程序来总结以下序列:1.0/1.0 + 1.0/2.0 + 1.0/3.0 .... + 1.0/15,000,000.0按升序排列然后再按降序从1.0/15,000,000.0 + 1.0开始14,999,999使用32位浮点一直下降到1.0/1.0.我正在努力弄清楚如何做到这一点,但这是我到目前为止(不知道它是否会起作用):

编辑:很抱歉打开这个东西,但我得到1.0的答案,我很确定这是不正确的.有谁知道我做错了什么?

public class FloatSum {

public static float increasingSum (float numbers1){
float sum1 = 0;
for (int i = 1; i <= 15000000; i++){ 
    sum1 = sum1 + 1/i; 
    } 
return sum1;
} 

public static float decreasingSum (float numbers2){
float sum2 = 0;
for (int i = 15000000; i >= 1; i--){ 
    sum2 = sum2 + 1/i; 
    } 
return sum2;
}

public static void main(String[] args) {
float sum1 = …
Run Code Online (Sandbox Code Playgroud)

java floating-point sum

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

Java中的Quicksort

我应该在java中做一个快速排序算法来排序数组{50,20,65,30,75,25,90}.这是我到目前为止:

public class QuickSort {
public static int partition(int arrayName[], int down, int up){
    int i = down, j = up;
    int temp;
    int pivot = arrayName[(down + up) / 2];

    while (i <= j){
        while (arrayName[i] < pivot)
            i++;
        while (arrayName[j] > pivot)
            j--;
        if (i <= j){
            temp = arrayName[i];
            arrayName[i] = arrayName[j];
            arrayName[j] = temp;
            i++;
            j--;

        }
    }
    return i;

}
public static void main(String[] args) {
    int [] arrayName = {50, 20, 65, 30, 75, …
Run Code Online (Sandbox Code Playgroud)

java quicksort

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