小编flo*_*olu的帖子

Angular 7 - 使用 queryParams 定义路由

我想声明两条 Angular 路线:

  1. 对于特定项目 ( /items?id=SOME_ITEM_ID)
  2. 对于所有项目的列表 ( /items)

由于以下不起作用,我想知道如何定义我的路线以满足我的需求?

export const routes: Routes = [
    { path: 'items?id=someItemId', component: ItemComponent },
    { path: 'items', component: AllItemsComponent },
];
Run Code Online (Sandbox Code Playgroud)

url typescript angular-routing angular angular7

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

NgRx 8 测试 provideMockStore - 状态切片的 setState

我的 NgRx 实现有一个智能组件测试,如下所示:

describe( 'Component', () => {
  let store: MockStore<State>;

  beforeEach( async( () => {
    TestBed.configureTestingModule( {
        /* ... */
        providers: [
            provideMockStore( { initialState: fromReducer.initialState } )
        ]
    } ).compileComponents();
    store = TestBed.get<Store<State>>( Store );
  } ) );

  it( 'should load items in #ngOnInit', () => {
    store.setState( {
        item: {
          ...fromReducer.initialState,
          entities: { [item.id]: item },
        },
        otherFeature: null,
        otherFeature: null,
        otherFeature: null
    } );
    component.items$.subscribe( items =>
        store.select( ItemStoreSelectors.selectItems ).subscribe( fromStore => expect( items ).toEqual( fromStore …
Run Code Online (Sandbox Code Playgroud)

typescript ngrx angular ngrx-store angular-test

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

Bazel - 错误:缺少输入文件“//server:files/src/index.js”

我想编译一些 Typescript 文件并从编译的 Javascript 文件创建一个 Node.js 图像。当我只有一个带有此BUILD文件的Typescript 文件时,它工作正常:

load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")

ts_library(
    name = "compile",
    srcs = ["src/index.ts"],
)

filegroup(
    name = "files",
    srcs = ["compile"],
    output_group = "es5_sources",
)

nodejs_image(
    name = "server",
    entry_point = "files",
)
Run Code Online (Sandbox Code Playgroud)

但是一旦我像这样引入多个Typescript 文件:

load("@io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
load("@npm_bazel_typescript//:index.bzl", "ts_library")

ts_library(
    name = "compile",
    srcs = ["src/index.ts", "src/util.ts"],
)

filegroup(
    name = "files",
    srcs = ["compile"],
    output_group = "es5_sources",
)

nodejs_image(
    name = "server",
    data = ["files"],
    entry_point = …
Run Code Online (Sandbox Code Playgroud)

javascript node.js typescript bazel

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

在条纹元素上使用 CSS 变量

我正在使用Stripe Elements信用卡结帐。问题是,我不能(或者我根本不知道如何)CSS variables在这个Stripe Element. CSS variables当用户更改主题时,我需要使用以更改颜色。这是我目前的实现:

变量定义(我使用的是 SASS)

.theme1
    --color-1: red
    --color-2: pink
    // ...
.theme2
    --color-1: blue
    --color-2: lilec
    // ...
.theme3
    --color-1: orange
    --color-2: yellow
    // ...
// ...
Run Code Online (Sandbox Code Playgroud)

CSS variables是一类的范围内,即投入到在限定的body当前选择取决于哪个主题。

HTML(我使用的是 Angular 6)

<div #stripe></div>
Run Code Online (Sandbox Code Playgroud)

打字稿

    @ViewChild('stripe') el: ElementRef;
    card: any;
    cardHandler = this.onChange.bind(this);
    async onSubmit() { /* ... */ }

    setupStripe(): void {
        this.card = stripeElements.create('card', {
            iconStyle: 'solid',
            style: {
                base: { …
Run Code Online (Sandbox Code Playgroud)

html css sass stripe-payments angular

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

从 Node.js 中的 .rar 文件中读取所有文件名

我有一条快速路线,可以上传文件,并通过formData.

假设文件是​​一个.rar文件,我的目标是提取此存档或其子文件夹中的所有文件名。

这是我的快递路线目前的样子:

module.exports = async (req, res) => {
    try {
        const busboy = new Busboy({ headers: req.headers })
        busboy.on('finish', async () => {
            const fileData = req.files.file
            console.log(fileData)
            // upload file
            // send back response
        })
        req.pipe(busboy)
    } catch (err) { return response.error(req, res, err, 'uploadProductFile_unexpected') }
}
Run Code Online (Sandbox Code Playgroud)

这是console.log(fileData)外观:

{
    data:
        <Buffer 52 61 72 21 1a 07 01 00 56 0c 22 93 0c 01 05 08 00 07 01 01 …
Run Code Online (Sandbox Code Playgroud)

javascript rar archive winrar node.js

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

无法安装夏普

运行时sudo npm i sharp --save出现以下错误:

> sharp@0.21.3 install /home/server/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Using cached /home/ronny/.npm/_libvips/libvips-8.7.0-linux-x64.tar.gz
ERR! sharp EACCES: permission denied, mkdir '/home/server/node_modules/sharp/vendor'
info sharp Attempting to build from source via node-gyp but this may fail due to the above error
info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
gyp ERR! configure error 
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/server/node_modules/sharp/build'
gyp ERR! System Linux …
Run Code Online (Sandbox Code Playgroud)

node.js npm sharp

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

Docker + WebGL + Headless Chrome 错误:不支持直通,GL 已禁用

我想使用 3D 画布截取网页的屏幕截图,如下所示:

import {createServer} from 'http'
import puppeteer from 'puppeteer'

const url = "https://webglfundamentals.org/webgl/webgl-load-obj-w-extents.html";

async function main() {
const browser = await puppeteer.launch({
  args: [
    "--no-sandbox",
    "--use-gl=swiftshader",
    "--enable-webgl",
  ],
  headless: true,
  dumpio: true,
  defaultViewport: { width: 400, height: 300 },
});

const page = await browser.newPage();

await page.goto(url);
await page.waitForNetworkIdle();

await page.waitForSelector("#canvas");

const screenshot = await page.screenshot();
console.log(screenshot);
Run Code Online (Sandbox Code Playgroud)

在我的 Ubuntu 机器上本地运行代码工作正常,生成此图像: 画布的屏幕截图

在 Docker 容器( Ubuntu + Node.js + Chrome )中运行代码不起作用。它会截取屏幕截图,但 3D 画布不会渲染。

[end of stack trace]
[0927/180308.980024:ERROR:gpu_process_host.cc(961)] GPU process …
Run Code Online (Sandbox Code Playgroud)

webgl node.js docker google-chrome-headless puppeteer

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

通过 Javascript 开始文件下载

目前,我正在使用ahref。但我不希望客户端能够获取 URL。

<a href="URL">Download</a>
Run Code Online (Sandbox Code Playgroud)

因此,我只是想问如何通过 Javascript 启动文件下载。(假设我有可用的网址)

html javascript url file download

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

如何创建多色噪声着色器

我需要一个采用 3 种输入颜色并产生噪声的着色器,如下所示。借助“噪声纹理”和“颜色渐变”节点,在 Blender 中很容易实现。

我找到了这个 gist,这可能会解决我的问题。但我无法配置颜色。而且噪音看起来比 Blender 中的结果“更锐利”。

我需要为此编写自己的着色器还是有更简单的方法来使用 ThreeJS 实现这种效果?

shader glsl blender three.js

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

catch块中是否捕获已捕获的JavaScript异常?

try {
    await function1()
    await function2()
    await function3().catch(err => { /*...*/ })
} catch (err) { /*...*/ }
Run Code Online (Sandbox Code Playgroud)

我的问题是,即使异常已被" catch捕获" ,块是否捕获了由此发出function3的异常.catch(err => ...)


如果catch块捕获异常function3,我的问题是如何防止这种行为?

我的目标基本上是捕获这些函数的特定异常,并将catch块用于每个未处理的异常.

javascript error-handling try-catch

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