我有这个代码:
this.loading = true;
this.http.get<IUser[]>(Urls.users())
.subscribe(
response => {
this._values = <IUser[]>response;
this.root.next({'users': this._values});
},
e => console.log(e),
() => this.loading = false
);
Run Code Online (Sandbox Code Playgroud)
调用此代码的页面有一个微调器,当'loading'设置为'true'时显示.但是当请求以0.5秒完成时,微调器几乎没有显示,并且在页面上看起来很奇怪.
如何在完成之前等待1秒(不使用setTimeout())?
有没有办法延迟所有的http请求,而不必像上面的代码那样修改每个代码?
我想创建一个选项卡组件。这应该是最终结果:
<app-tab-container>
<app-tab-item caption="A">..contentA..</app-tab-item>
<app-tab-item caption="B">..contentB..</app-tab-item>
<app-tab-item caption="C">..contentC..</app-tab-item>
</app-tab-container>
Run Code Online (Sandbox Code Playgroud)
TabItemComponent 有一个 @HostBinding('hidden') 装饰字段:
export class TabItemComponent {
@HostBinding('hidden') isHidden = false;
@Input() caption: string;
}
Run Code Online (Sandbox Code Playgroud)
在 TabContainerComponent 中,我使用 @ContentChildren 遍历 tab-items :
export class TabContainerComponent {
@ContentChildren(TabItemComponent) items: QueryList<TabItemComponent>;
tabItems: string[] = [];
ngAfterContentInit() {
this.items.forEach((item, idx) => {item.isHidden = true; this.tabItems.push(item.caption));
}
}
Run Code Online (Sandbox Code Playgroud)
最后 TabContainerComponent 模板如下:
<div class="tab-title"
*ngFor="let caption of tabItems">{{caption}}</div>
<ng-content></ng-content>
Run Code Online (Sandbox Code Playgroud)
最终目标是通过单击事件切换选项卡项的可见性。
当我运行代码选项卡标题显示正确但内容本身(app-tab-item caption="A" 到 "C")仍然可见时,设置 isHidden 不会切换可见性。
请注意,我不知道“app-tab-item”组件的数量,因为我可能会将“app-tab-container”放置在其他内容不同的地方。
如何<app-tab-item>使用 @ContentChildren 以编程方式切换组件的可见性?
在很多帖子中,甚至在谷歌的网站上(这里)我都看到了这段代码:
// Set the alarm to start at approximately 2:00 p.m.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
Run Code Online (Sandbox Code Playgroud)
所以我在一个独立的Java程序(非Android)中进行了测试:
Calendar c = Calendar.getInstance();
System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(System.currentTimeMillis())));
System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(c.getTimeInMillis())));
Run Code Online (Sandbox Code Playgroud)
输出:
01:23:33.884
01:23:33.876
Run Code Online (Sandbox Code Playgroud)
它没有显式设置setTimeInMillis时工作正常.
calendar.setTimeInMillis(System.currentTimeMillis())的重点是什么?它是错误的,尤其是 在Android编程中,要不是这样设置的?
我有2条路线:
export const appRoutes: Route[] = [
{
path: 'page1',
component: Page1Component,
data: {
animation: 'page1'
}
},
{
path: 'page2',
component: Page2Component,
data: {
animation: 'page2'
}
},
];
Run Code Online (Sandbox Code Playgroud)
我的路线动画:
export const routeStateTrigger = trigger('routeState', [
transition('* => *', [
query(':enter', [
style({ position: 'absolute', opacity: 0 })
], { optional: true }),
query(':leave', [
animate(300, style({ opacity: 0 }))
], { optional: true }),
query(':enter', [
style({ position: 'relative', opacity: 0 }),
animate(300, style({ display: 'visible', opacity: 1 …Run Code Online (Sandbox Code Playgroud) 我有这样的文件结构:
---- _base-map.scss
---- _child-map-1.scss
---- _child-map-2.scss
---- _child-map-3.scss
styles.scss
Run Code Online (Sandbox Code Playgroud)
style.scss 导入所有子地图文件:
@import './base-map';
@import './child-map-1';
@import './child-map-2';
@import './child-map-3';
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好。
_base-map.scss :
$base-map : (
"font-size" : 1.3rem,
"border-radius" : 0.4rem,
// ...
);
Run Code Online (Sandbox Code Playgroud)
为了使用“map.merge”,必须包含@use“sass:map”:
_child-map-1.scss :
@use "sass:map";
$child-map-1 : map.merge(
$base-map,
(
"font-size" : 2rem,
"border-radius" : 0.5rem,
// ...
)
);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将文件与 scss-bundle 捆绑在一起时,出现此错误:
[17:22:37] erro: There is an error in your styles:
[17:22:37] erro: @use rules must be written before any other rules.
[17:22:37] erro: …Run Code Online (Sandbox Code Playgroud) 我有这个自定义组件:
<my-component [control]="..."></my-component>
Run Code Online (Sandbox Code Playgroud)
这里,控制定义为:
@Input() control: FormControl;
Run Code Online (Sandbox Code Playgroud)
我的组件的用法:
this.myFormGroup = new FormGroup({
name: new FormControl('')
});
<my-component [control]="myFormGroup.controls.name"></my-component>
Run Code Online (Sandbox Code Playgroud)
错误:
Angular 10 严格模式抱怨“myFormGroup.controls.name”不是一个 FormControl。
“控件”在 FormGroup 中定义为一个对象,其中每个字段都是 AbstractControl 类型:
// forms.d.ts
export declare class FormGroup extends AbstractControl {
controls: {
[key: string]: AbstractControl;
};
// ....
}
Run Code Online (Sandbox Code Playgroud)
这段代码可以在运行时运行,但不能编译。
解决这个问题的最佳方法是什么?
使用“ng new”创建新项目并修改 tslint.json 以使用制表符而不是空格后,运行“ng lint --fix=true”不会对 .ts 文件产生任何影响:
ng lint --fix=true
Run Code Online (Sandbox Code Playgroud)
仅列出错误,但不修复它们。根据文档,应该如此。
ERROR: 4:1 indent tab indentation expected
ERROR: 5:1 indent tab indentation expected
ERROR: 6:1 indent tab indentation expected
ERROR: 9:1 indent tab indentation expected
Run Code Online (Sandbox Code Playgroud)
环境:Angular CLI:10.1.7
命令是不是错了?
我将支持库更新到23.2.0.并改变了recyclerView的高度在博客WRAP_CONTENT为解释在这里:
RecyclerView小部件为创建列表和网格以及支持动画提供了高级灵活的基础.此版本为LayoutManager API带来了令人兴奋的新功能:自动测量!这允许RecyclerView根据其内容的大小调整自身大小.这意味着现在可以使用以前不可用的方案,例如使用WRAP_CONTENT作为RecyclerView的维度.您会发现所有内置的LayoutManagers现在都支持自动测量.
由于此更改,请务必仔细检查项目视图的布局参数:现在将完全遵循先前忽略的布局参数(例如滚动方向中的MATCH_PARENT).
编辑/添加评论:我必须这样做,因为更新'match_parent'做了它应该做的事后,它将cardviews高度拉伸到底部,所以我最终每页有一个cardview.
但是现在在刷新新创建的卡片视图后,它们之间又有了不必要的空间.
让我进一步澄清:
有没有人遇到过这种行为?
我有一个简单的控制器方法:
@GetMapping("/search")
public List<Result> search(@RequestParam @Valid @NotNull @Size(min = 4) String query) {
return searchService.search(query);
}
Run Code Online (Sandbox Code Playgroud)
当我省略“查询”参数时,正如预期的那样,我收到 400 Bad Request。
使用这些查询参数测试方法不起作用。
除了最后一个测试之外,所有测试都应该返回“400 Bad Request”。
"/search" --> actual 400 Bad Request, test passes
"/search?query=" --> actual 200 Ok, expected 400 because @Size(min=4)
"/search?query=a" --> actual 200 Ok, expected 400 because @Size(min=4)
"/search?query=ab" --> actual 200 Ok, expected 400 because @Size(min=4)
"/search?query=abc" --> actual 200 Ok, expected 400 because @Size(min=4)
"/search?query=abcd" --> actual 200 Ok, test passes
Run Code Online (Sandbox Code Playgroud)
为什么 @Size(min=4) 注释被忽略?
我有这个 ActionButtonComponent,它使用 Angular CDK Portal:
import { CdkPortal, DomPortalHost } from '@angular/cdk/portal';
import { AfterViewInit, ApplicationRef, Component, ComponentFactoryResolver, Injector, OnDestroy, ViewChild } from '@angular/core';
@Component({
selector: 'app-action-button',
template: `
<ng-container *cdkPortal>
<ng-content></ng-content>
</ng-container>
`
})
export class ActionButtonComponent implements AfterViewInit, OnDestroy {
@ViewChild(CdkPortal)
private portal: CdkPortal;
private host: DomPortalHost;
constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private applicationRef: ApplicationRef,
private injector: Injector
) { }
ngAfterViewInit(): void {
this.host = new DomPortalHost(
document.querySelector('#action'),
this.componentFactoryResolver,
this.applicationRef,
this.injector
);
console.log(this.portal); // <-- logs "undefined"
console.log(document.querySelector('#action')); …Run Code Online (Sandbox Code Playgroud) angular ×6
android ×2
angular-cdk ×1
angular-cli ×1
css ×1
java ×1
lint ×1
rest ×1
rxjs ×1
sass ×1
spring ×1
spring-boot ×1
validation ×1