timeout
当参数isTimeoutNeeded
为True时,我需要一个运算符引发错误,以便我处理已订阅的observable在X秒后不发出任何值的情况。
if (isTimeoutNeeded) {
this.service.getData()
.pipe(
timeout(10000),
...
)
.subscribe((...) => ...);
} else {
this.service.getData()
.pipe(
...
)
.subscribe((...) => ...);
}
Run Code Online (Sandbox Code Playgroud)
是否可以通过timeout
在需要时有条件地添加运算符来以rxjs方式编写此代码?
我尝试使用iif
,switchMap
但是没有用。
this.service.getData()
.pipe(
mergeMap((response) =>
iif(() => !isTimeoutNeeded,
of(response),
of(response).pipe(timeout(10000)) // did not apply timeout if isTimeoutNeeded = True
)
)
.subscribe((...) => ...);
Run Code Online (Sandbox Code Playgroud)
switchMap
this.service.getData()
.pipe(
switchMap((response) => {
if (!isTimeoutNeeded) {
return of(response);
}
return of(response).timeout(10000); // did not apply timeout if isTimeoutNeeded = True …
Run Code Online (Sandbox Code Playgroud) for (Keys k = Keys.A; k <= Keys.Z; k++)
{
if (KeyPress(k))
Text += k;
}
Run Code Online (Sandbox Code Playgroud)
此代码检测到我在键盘上按下的按键按钮,它将打印出在控制台中按下的按键.但是,我在键盘上按了'a',但它出现'A'.我该如何解决?
父组件如何将多个 ng-template 传递给子组件?
例如,父组件包含多个 ng-template:
<app-childcomponent>
<ng-template>Item A</ng-template>
<ng-template>Item B</ng-template>
...
</app-childcomponent>
Run Code Online (Sandbox Code Playgroud)
子组件需要从父组件接收 ng-templates 并将其放入其中app-menu
:
<app-menu>
<ng-content></ng-content>
</app-menu>
Run Code Online (Sandbox Code Playgroud)
所以它在子组件中看起来像这样:
<app-menu>
<ng-template>Item 1</ng-template> //having trouble sending this to app-menu from parent
<ng-template>Item 2</ng-template> //having trouble sending this to app-menu from parent
<app-menu>
Run Code Online (Sandbox Code Playgroud)
但似乎是ng-content
空的导致app-menu
没有得到multiple ng-templates
。
<app-menu>
//empty
</app-menu>
Run Code Online (Sandbox Code Playgroud)
我尝试了什么?
我尝试通过@input传递模板。<app-childcomponent [myTemplate]="myTemplate"></child-component>
模板出口。结果:子组件无法获取ng-templates
.
父级 HTML:
<app-childcomponent>
<ng-template>Item 1</ng-template>
<ng-template>Item 2</ng-template>
</app-childcomponent>
Run Code Online (Sandbox Code Playgroud)
家长班级:
@ContentChild(TemplateRef) templateRef: TemplateRef<any>;
Run Code Online (Sandbox Code Playgroud)
子 HTML:
<app-menu>
<ng-template [ngTemplateOutlet]="templateRef"></ng-template>
<app-menu>
Run Code Online (Sandbox Code Playgroud)
预计 …
我是XNA C#中的新手,我想知道如何在XNA C#中创建一个每秒都会闪烁的模型.我正试图为我的模型制造一个无懈可击的效果.
目前,我自己的想法是,我会将模型的可见性设置为假而真实.
谢谢.
编辑:我model.visible = false
在XNA C中找不到任何#?
如何播放背景音乐并使其循环播放?
目前我正在使用这段代码来播放背景音乐:
XNA-C#
SoundEffect bgEffect;
bgEffect = Content.Load<SoundEffect>("EpicUnease");
bgEffect.Play(0.1f, 0.0f, 0.0f);
Run Code Online (Sandbox Code Playgroud) 将玩家名称添加到列表中:
chatList0.Add(s);
Run Code Online (Sandbox Code Playgroud)
将播放器消息添加到列表中:
chatList.Add(s);
Run Code Online (Sandbox Code Playgroud)
以不同颜色打印播放器名称和消息:
for (int i = 0; i < chatList0.Count(); i++)
{
//draw system msg (contains name/time/etc)
spriteBatch.DrawString(font, chatList0[i], new Vector2(40, arr1[i]), Color.Yellow);
//check length of system msg
Vector2 offset = textEntry.GetMeasurements(font, chatList0[i]);
//draw msg after offset
spriteBatch.DrawString(font, chatList[i], new Vector2(offset.X + 40, arr1[i]), Color.White);
}
Run Code Online (Sandbox Code Playgroud)
它是否正确?是否需要进行任何更改以优化代码?
carArray
从用户过滤一定的条件.
当用户选中red
复选框时,它将过滤带有红色油漆的汽车.当用户选中green
复选框时,它将过滤带有绿色涂料的汽车.当用户同时选中red
和green
复选框时,它将显示红色和绿色汽车.(等N个用户条件)
我在这个例子中使用了2个复选框.我的实际实现中有超过5个复选框.
我开始用showRed
,showGreen
布尔瓦尔来跟踪用户想要什么,数组car
对象.
[ {
carName: xxx,
color: 'red'
},
{
carName: yyy,
color: 'green'
},
.....
]
filteredCars = carArray.filter((car) => {
// Problem: I tried to check for showRed and
// showGreen before returning but found out that I can
// only return once in here
if (showRed) {
return car.color === 'red';
}
if (showGreen) {
return car.color === 'green';
} …
Run Code Online (Sandbox Code Playgroud) c# ×4
angular ×3
xna ×3
javascript ×2
typescript ×2
background ×1
html ×1
key ×1
loops ×1
playback ×1
rxjs ×1