小编rra*_*rag的帖子

Angular 2+:基于api响应的路由

说我有以下内容

const routes = [
  { 
    path: 'product/:id',
    component: ProductDetailsComponent,
  }
  { 
    path: 'search',
    component: SearchResultsComponent,
  }
]
Run Code Online (Sandbox Code Playgroud)

现在说

product/1 - 是一部由电影呈现的电影 DigitalMediaComponent

product/2 - 是说电视 ProductDetailsComponent

product/3 - 是一个洗衣机/烘干机捆绑,呈现为 BundleComponent

product/4 - 是一个床垫系列,这包括,床垫,框架,封面,床单,枕头,一旦可以选择一些东西,颜色,尺寸,线程数等购买之前

product/5- 是一种汽车产品说轮胎,所以这使得TireComponent- 这需要一个配件模块,年份/品牌/型号/装饰选择,以及许多其他定制,然后才能购买

而这样的例子不胜枚举.

显然,有些组件在其中一些组件之间重复使用,但总的来说它们之间存在很大差异.所以我想懒加载(或懒惰下载)包含这些组件的javascript文件(和css),我不需要MoviePreviewComponent显示轮胎时.

我已经阅读了很多例子,他们都谈到了一个非常简单的路由和组件之间的一对一关系的情况,比如

{ path: 'product/:id', loadChildren: 'product/ProductDetailsComponent' }
or
{ path: 'product/:id', loadChildren: () => System.import('./product/ProductDetailsComponent').then(mod => mod.default) }
Run Code Online (Sandbox Code Playgroud)

我有办法吗?

  1. 在导航到路线时呼叫api
  2. 并根据对api的响应System.import('...')用于懒惰下载模块

我不想导航到插页式广告组件并从那里加载,因为当用户点击搜索结果中的产品时(或整个网站中的任何其他促销横幅,可能会或可能不会使用角度2构建),以及如果页面加载需要一些,他们可以按下esc并单击其他内容.这是正常的浏览器行为,我不想失去它

即使我最终得到插页式组件,我将如何加载动态模块呢?

ngOnInit() {
  let id = this.route.snapshot.params['id'];
  fetch('/my/api/' + id) …
Run Code Online (Sandbox Code Playgroud)

angular

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

Stripe checkout - 删除电子邮件字段或将其设置为只读

我正在使用https://stripe.com/docs/ payments/checkout 中所述的 stripe checkout

在服务器端,我创建一个新的 stripe 客户(如果还没有),并使用该客户 ID 创建结账会话。然后使用 stripe api 重定向到结账

stripe.redirectToCheckout({
  // Make the id field from the Checkout Session creation API response
  // available to this file, so you can provide it as parameter here
  // instead of the {{CHECKOUT_SESSION_ID}} placeholder.
  sessionId: '{{CHECKOUT_SESSION_ID}}'
}).then(function (result) {
  // If `redirectToCheckout` fails due to a browser or network
  // error, display the localized error message to your customer
  // using `result.error.message`.
});
Run Code Online (Sandbox Code Playgroud)

在结帐页面(由条带托管)中,有一个已预先填充但可编辑的电子邮件字段。我已经让客户更改了该电子邮件地址。有没有办法使条纹结帐只读字段上的电子邮件地址?

javascript email checkout readonly stripe-payments

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

在 `flex-grow: 1` 内垂直居中

说我有 HTML 作为

<div class="page">
  <div class="header"></div>
  <div class="content">
    <div class="foo">
      <div>I want to be center of content</div>
    </div>
  </div>
  <div class="footer"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

html, body {
  height: 100%;
}
body {
  margin: 0;
}

.page {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.header {
  flex-shrink: 0;
  background-color: green;
  height: 50px;
}
.content {
  flex-grow: 1;
}
.footer {
  flex-shrink: 0;
  background-color: steelblue;
  height: 150px;
}

.foo {
  display: flex;
  justify-content: center;
  align-items: center;
}
Run Code Online (Sandbox Code Playgroud)

https://codepen.io/rrag/pen/PRmOYe

我使用以下方法在页面底部实现了粘性页脚,flex-grow但这会导致内容高度未知 …

css flexbox

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

Stripe 订阅在付款成功后更新计费周期锚

假设我有一个 stripe 订阅(从 2021 年 10 月 1 日开始),并在 2021 年 11 月 1 日第一个计费周期结束时

  1. stripe 尝试对存档的卡进行收费
  2. 假设交易因资金不足而失败
  3. 2天后(2021-11-03)再次stripe重试,这次交易成功。

现在,即使之前的付款已于 2021 年 11 月 3 日完成,订阅仍将在 2021 年 12 月 1 日再次向用户收取费用

当用户付款未完成时,我不向用户提供服务(2021-11-01至2021-11-03)

此处的最佳做法是什么,以便下次收费发生在 2021 年 12 月 3 日(而不是 2021 年 12 月 1 日)?

stripe-payments

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

多个sync.WaitGroup的使用

我见过几个不同的例子sync.WaitGroup

实施例1

var wg sync.WaitGroup

wg.Add(1)
go doStuff(&wg)
wg.Wait()
Run Code Online (Sandbox Code Playgroud)

实施例2

wg := new(sync.WaitGroup)

wg.Add(1)
go doStuff(wg)
wg.Wait()
Run Code Online (Sandbox Code Playgroud)

区别实际上在于sync.WaitGroup初始化 方式varnew

如果使用该var选项,它必须作为&wg指向 goroutine 的指针传递,但如果我使用该new选项,我可以将其发送为wg

这两个例子有什么区别?上面这2个哪一个是正确的?在某些情况下,是否优先选择其中一种?

我正在编写一个创建多个 s 的程序,那么使用orsync.WaitGroup是否重要?newvar

concurrency pointers go

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