小编Tom*_*Tom的帖子

基于角度(v2 +)的路径路径设置动画路线

而不是将动画附加到正在路由到的每个组件,例如在此StackOverflow答案中,或者在官方文档第一部分中.一个例子:

hero-detail.component.ts:

import { Component, OnInit } from '@angular/core';
import { fadeInOutAnimation } from "app/app-routing.animation";

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  animations: [
    fadeInOutAnimation(300)
  ]
})
export class HomeComponent{       

}
Run Code Online (Sandbox Code Playgroud)

app-routing.animation.ts:

import {
  trigger,
  state,
  style,
  animate,
  transition
} from '@angular/animations';

export const fadeInOutAnimation = function (fadeInTimeMS) {
  return trigger('fadeInOut', [
    transition(':enter', [   // :enter is alias to 'void => *'
      style({ opacity: 0 }),
      animate(fadeInTimeMS, style({ opacity: 1 }))
    ]), …
Run Code Online (Sandbox Code Playgroud)

javascript animation angular

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

有没有办法部分地构造一个结构?

我有一个结构:

struct ThreeDPoint {
    x: f32,
    y: f32,
    z: f32
}
Run Code Online (Sandbox Code Playgroud)

我想在实例化之后提取三个属性中的两个:

let point: ThreeDPoint = ThreeDPoint { x: 0.3, y: 0.4, z: 0.5 };
let ThreeDPoint { x: my_x, y: my_y } = point;
Run Code Online (Sandbox Code Playgroud)

编译器抛出以下错误:

error[E0027]: pattern does not mention field `z`
  --> src/structures.rs:44:9
   |
44 |     let ThreeDPoint { x: my_x, y: my_y } = point;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `z`
Run Code Online (Sandbox Code Playgroud)

在JavaScript(ES6)中,等效的解构将如下所示:

let { x: my_x, y: my_y } = point;
Run Code Online (Sandbox Code Playgroud)

destructuring rust

9
推荐指数
2
解决办法
1436
查看次数

有没有办法使用 Kustomize 添加新资源(而不是覆盖它们)?

使用kubectl apply -k,您可以覆盖资源配置(您已经定义)。你也可以创建资源吗?

\n\n

在我的具体情况下,我想为开发环境创建一个本地卷。不过,我的基本文件夹中没有此资源。

\n\n

我的文件夹结构是这样的:

\n\n
\n
~/someApp\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 base\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 deployment.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 service.yaml\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 overlays\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 development\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cpu_count.yaml\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 replica_count.yaml\n    \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 volume.yaml <--- *Is this possible*?\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 production\n        \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 cpu_count.yaml\n        \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 kustomization.yaml\n        \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 replica_count.yaml\n
Run Code Online (Sandbox Code Playgroud)\n
\n

templating kubernetes kustomize

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

如何在打字稿元组中使用扩展运算符?

我想指定数组的其余部分应该如何显示,而不知道数组将有多少个值。我怎样才能实现这样的目标?(这里是游乐场版本):

type numStrArr = [number, ...string];

let arr: numStrArr = [1, 'hi', 'other string'];
Run Code Online (Sandbox Code Playgroud)

Type expected.然而,上面的代码在扩展运算符处抛出了错误。

我知道有人对此提出建议,但现在我怎样才能实现类似的行为呢?

types tuples typescript spread-syntax

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

匹配浮点的替代方法

Rust决定在模式中禁止float文字:完全允许匹配浮点文字值,不应该是#41255.它目前是一个警告,但在将来的版本中将是一个很难的错误.

我的问题是,如何使用以下代码实现等效?:

struct Point {
    x: f64,
    y: f64,
}

let point = Point {x: 5.0, y: 4.0};

match point {
    Point {x: 5.0 , y} => println!("y is {} when x is 5", y), // Causes warning
    _ => println!("x is not 5")
}
Run Code Online (Sandbox Code Playgroud)

现在不可能吗?我是否需要改变对模式的看法?还有另一种匹配方式吗?

pattern-matching match rust

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

如何在WebStorm中保存TSLint?

我怎样才能解决我的.ts文件,每次我保存在一个文件WebStorm

我知道我可以tslint --fix在保存后跑步.我也知道我可以⌥⏎+ 在文件中的当前错误,并将解决该错误.但我已经习惯了不同的样式指南,它可以节省我很多时间来自动修复这些样式lint错误:

tslint错误

我在WebStorm中找不到相关设置:

WebStorm设置

我也完全愿意使用不同的cli工具来实现保存时的自动创作.

webstorm typescript tslint

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

如何获得元组的长度?

这是我尝试过的行为:

struct Matrix(f32, f32, f32, f32);
let matrix = Matrix(1.1, 1.2, 2.1, 2.2);
matrix.len();    // expected `4`
Run Code Online (Sandbox Code Playgroud)

这会产生错误:

struct Matrix(f32, f32, f32, f32);
let matrix = Matrix(1.1, 1.2, 2.1, 2.2);
matrix.len();    // expected `4`
Run Code Online (Sandbox Code Playgroud)

std::iter::ExactSizeIterator看起来是一个不错的候选人,但我仍然不知道如何实施

语境

在尝试反向时Matrix,我意识到不要像这样干巴巴地列出矩阵的反向索引:

fn reverse(matrix: Matrix) -> Matrix {
    return Matrix(matrix.3, matrix.2, matrix.1, matrix.0)
}
Run Code Online (Sandbox Code Playgroud)

我也许可以按Matrix相反的顺序迭代。我看到如何迭代或映射元组?并认为这很复杂。如果能够获得元组的长度,就可以解决“如何迭代或映射元组?”这一问题。有一个更简单的解决方案。显然,我可以只使用“4”作为长度,但是如果我不使用结构体而是使用未知长度的元组怎么办?

tuples traits rust

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

如何在没有for循环的情况下获取迭代中正在处理的当前元素的索引?

我已阅读如何使用索引位置迭代 Vec<T>?答案是enumeratefor-loop 中使用。

但是,如果我不使用这样的for-loop:

fn main() {
    let v = vec![1; 10]
        .iter()
        .map(|&x| x + 1  /* + index */ ) // <--
        .collect::<Vec<_>>();

    print!("v{:?}", v);
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在上面的闭包中获得索引?

rust

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

在typescript中定义typeof抽象类

我如何在typeof BaseListComponent下面指定?

下面的代码引发以下错误:

类型' ({ title: string; component: typeof QuestionsListComponent; } | { title: string; component: ...'不能分配给类型'{ title: string; component: typeof BaseListComponent; }[]'.

摘抄:

abstract class BaseListComponent {
  protected title
}

class WeatherListComponent extends BaseListComponent {}

class QuestionsListComponent extends BaseListComponent {}

let containerItems: Array<{title: string, component: typeof BaseListComponent}>;
containerItems = [
  {title:'TypeScript', component: QuestionsListComponent},
  {title:'Angular2', component: QuestionsListComponent},
  {title:'Weather', component: WeatherListComponent}
]
Run Code Online (Sandbox Code Playgroud)

PS这是一个角度应用程序的简化摘录,所以这种疯狂背后有逻辑.

abstract-class types class typescript angular

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

当mongo文档中有超过7个子文档时,远程服务器上的net :: ERR_CONNECTION_CLOSED

我正在开发一个角度为4.1.0的MEAN项目.

在我的localhost上,一切正常,没有错误.但是,当我部署到服务器时,检索具有8个以上问题 - 答案对的用户会导致在角度的http模块触发的xhr请求上出现net :: ERR_CONNECTION_CLOSED错误.

我托管的数字海洋小滴使用nginx反向代理并使用letsencrypt SSL证书.我试过了:

  • 重启服务器,nginx服务,node.js等.
  • 增加client_max_body_size20M在nginx的配置文件
  • large_client_header_buffers'size'增加到128knginx配置文件中

其他重要事实:

  • 永远不会到达node.js应用程序的GET请求qapairs?jwt=ey..
  • 没有提到请求 /var/log/nginx/error.log
  • 显示的失败请求/var/log/nginx/access.log如下:

    89.15.159.19 - - [08/May/2017:14:25:53 +0000] "-" 400 0 "-" "-"
    89.15.159.19 - - [08/May/2017:14:25:53 +0000] "-" 400 0 "-" "-"
    
    Run Code Online (Sandbox Code Playgroud)

请指出我可能的方向.


chrome dev工具网络选项卡截图

  1. 登录到只有7个问题答案对的帐户后 登录到只有7个问题答案对的帐户后

  2. 然后,在转到mlab.com并手动将另一个问题答案对添加到同一帐户然后刷新页面(注意现在的问题数量为8) 转到mlab.com并手动将另一个问题答案对添加到同一帐户然后刷新页面

  3. 最后,登录和退出同一帐户后(注意xhr请求qapairs?jwt=ey...返回失败状态) 登录和退出同一帐户后

在/ etc/nginx的/启用的站点 - /默认

# HTTP — redirect all traffic to HTTPS
server {
    listen 80;
    listen [::]:80 default_server …
Run Code Online (Sandbox Code Playgroud)

ssl nginx mongodb node.js http2

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

如何定义特征上的可选方法?

Rust是否有一个功能,我可以创建定义特征上可能不存在的方法?

我意识到这Option可以用来处理可能不存在的属性,但我不知道如何用方法实现相同.

在TypeScript中,问号表示方法可能不存在.以下是RxJs的摘录:

export interface NextObserver<T> {
  next?: (value: T) => void;
  // ...
}
Run Code Online (Sandbox Code Playgroud)

如果Rust中不存在此功能,那么应该如何考虑处理对象,程序员不知道方法是否存在?恐慌?

interface custom-type rust

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

如何在WebStorm中悬停时启用intellisense/JSDoc信息?

Visual Studio中的行为是我想要的.像这样:

在此输入图像描述

或者像这样:

在此输入图像描述

目前,我在悬停时得不到任何东西,只有输入时基本类型信息:

在此输入图像描述

这是可能的,如果是的话,怎么样?

intellisense jsdoc webstorm

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

为什么我不能两次反转迭代器来获取向量的最后两个数字?

我想取一个向量的最后两个数字.为什么我不能两次反转迭代器?

fn main() {
    let double_reversed = &vec![1, 2, 3, 4, 5, 6, 7, 8, 9]
        .into_iter()
        .rev()
        .take(2)
        .rev()
        .collect();

    println!("{}", double_reversed); // expected 8, 9
}
Run Code Online (Sandbox Code Playgroud)

操场

错误消息是:

error[E0277]: the trait bound `std::iter::Take<std::iter::Rev<std::vec::IntoIter<{integer}>>>: std::iter::DoubleEndedIterator` is not satisfied
 --> src/main.rs:6:10
  |
6 |         .rev()
  |          ^^^ the trait `std::iter::DoubleEndedIterator` is not implemented for `std::iter::Take<std::iter::Rev<std::vec::IntoIter<{integer}>>>`

error[E0599]: no method named `collect` found for type `std::iter::Rev<std::iter::Take<std::iter::Rev<std::vec::IntoIter<{integer}>>>>` in the current scope
 --> src/main.rs:7:10
  |
7 |         .collect();
  |          ^^^^^^^
  |
  = note: the …
Run Code Online (Sandbox Code Playgroud)

iterator functional-programming rust

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