我有一个包含默认隐藏的 textarea 的组件:
<div class="action ui-g-2" (click)="toggleEditable()">edit</div>
<textarea [hidden]="!whyModel.inEdition" #myname id="textBox_{{whyModel.id}}" pInputTextarea focus="true" [(ngModel)]="whyModel.description"></textarea>
Run Code Online (Sandbox Code Playgroud)
当我单击“编辑”div 时,我想显示 textarea 并将焦点放在它上面:
@ViewChild('myname') input: ElementRef;
...
private toggleEditable(): void {
this.whyModel.toggleEditable();
this.input.nativeElement.focus();
}
Run Code Online (Sandbox Code Playgroud)
“显示”部分正在工作,但不是重点部分。我想念什么?
我尝试在一个组件上编写我的第一个单元测试,其中使用了一些 Primeng 组件。
当我运行“ng test”时,出现此错误:
Chrome 63.0.3239 (Linux 0.0.0) HeaderComponent should create FAILED
1. If 'p-dropdown' is an Angular component and it has 'ngModel' input, then verify that it is part of this module.
2. If 'p-dropdown' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("header-text">
<p-dropdown [options]="languages" (onChange)="onDropdownChange($event.value)" [ERROR ->][(ngModel)]="selectedLanguage"></p-dropdown>
</div>
Run Code Online (Sandbox Code Playgroud)
不确定我需要做什么?我需要注入或模拟任何东西吗?
这是我的单元测试(基本上是生成的):
describe('HeaderComponent', () => { …Run Code Online (Sandbox Code Playgroud) 我有一些实现某些接口的对象,但它们也有额外的属性.当我来序列化它们(保存在文件中)时,我想删除所有额外的属性,并且只保留与接口匹配的属性.
有没有办法"清理"关于给定接口的对象.我正在努力
Object.getOwnPropertyNames(myObject)
Run Code Online (Sandbox Code Playgroud)
要获取对象属性的完整列表,并与接口属性的完整列表进行比较,但我找不到获取接口属性列表的方法
编辑:我在这里找到了一种方法:如何根据TypeScript中的接口文件定义创建对象?
同
var object = <IMyInterface>{};
Run Code Online (Sandbox Code Playgroud)
但是我看到当我使用Object.getOwnPropertyNames(myObject)时,这只适用于已定义的属性,如果未定义属性,则它不在结果中.有没有一种方法可以获得所有可用的属性,而不仅仅是已定义的属性?
我需要在菜单条目中添加一些 html 代码,因此我尝试使用自定义显示:
我的模板:
<p-panelMenu styleClass="main-menu" class="main-menu" [model]="menus">
<ng-template let-menus pTemplate>
{{menus.label}} <span>otherStuff</span>
</ng-template>
</p-panelMenu>
Run Code Online (Sandbox Code Playgroud)
组件:
this.menus = [
{
label: 'Dashboard',
icon: 'fa-home',
routerLink: '/home'
},
...
Run Code Online (Sandbox Code Playgroud)
什么也没发生,它仍然显示菜单,就好像我没有添加模板一样。我想念什么?
我是 Reactive Forms 的新手,我习惯于使用模板驱动的表单。
我正在关注这里的教程:https : //angular-templates.io/tutorials/about/angular-forms-and-validations
我有一个用户类:
export class User {
public pseudo: string;
public email: string;
public password: string;
public constructor(init?: User) {
Object.assign(this, init);
}
}
Run Code Online (Sandbox Code Playgroud)
我在一个组件中得到了我的 FormGroups:
this.matching_passwords_group = new FormGroup(
{
password: new FormControl(
'',
Validators.compose([
Validators.minLength(5),
Validators.required,
Validators.pattern(
'^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[a-zA-Z0-9]+$'
)
])
),
confirm_password: new FormControl('')
},
(formGroup: FormGroup) => {
return PasswordValidator.areEqual(formGroup);
}
);
// user details form validations
this.userDetailsForm = this.fb.group({
pseudo: new FormControl('', Validators.required),
email: new FormControl(
'',
Validators.compose([
Validators.required,
Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$') …Run Code Online (Sandbox Code Playgroud) 我尝试将通过输入文件获得的文件转换为byte [].我尝试使用FileReader,但我必须错过一些东西:
var bytes = [];
var reader = new FileReader();
reader.onload = function () {
bytes = reader.result;
};
reader.readAsArrayBuffer(myFile);
Run Code Online (Sandbox Code Playgroud)
但最后,我的bytes var不满足字节数组.
我看到这篇文章:通过input type = file获取字节数组,但它不以byte []结尾,并且不推荐使用readAsBinaryString()
我错过了什么?
我需要匿名数据库中的电子邮件,所以我尝试设置一个查询,但我找不到为每个生成唯一随机字符串的方法。到目前为止我所拥有的是:
update candidate set email = (select CONCAT(SUBSTRING(MD5(RAND()) FROM 1 FOR 15) , '@test.fr'));
Run Code Online (Sandbox Code Playgroud)
但显然该值不是唯一的,这可以通过简单的查询实现吗?
我在这里尝试了解决方案:https : //harrybailey.com/2015/08/mysql-roughly-random-string-generation-for-updating-rows/但同样的结果,我得到了
错误代码:1062。密钥“电子邮件”的重复条目“0417da5fb3d071b9bd10”
我有一个 mat-menu,其中内容可能因用户而异。我尝试编写单元测试,但从我所看到的情况来看,茉莉花看不到 CDK div,所以我无法获取菜单条目。
我的模板:
\n<button id="account" mat-icon-button [matMenuTriggerFor]="menu" aria-label="Profile">\n <mat-icon>person</mat-icon>\n</button>\n<mat-menu #menu="matMenu">\n <button mat-menu-item *ngxPermissionsOnly="PERMISSION.USER_LIST" id="user-list" (click)="usersList()">\n <mat-icon>recent_actors</mat-icon>\n </button>\n <button mat-menu-item *ngxPermissionsOnly="PERMISSION.INFORMATIONS" id="informations" (click)="infoList()">\n <mat-icon>info</mat-icon>\n </button>\n <button mat-menu-item id="logout" (click)="logout()">\n <mat-icon>exit_to_app</mat-icon>\n </button>\n</mat-menu>\nRun Code Online (Sandbox Code Playgroud)\n单元测试:
\nlet component: HeaderComponent;\nlet fixture: ComponentFixture < HeaderComponent > ;\n\nconst providers: any[] = headerProviders;\n\nbeforeEach(async (() => {\n TestBed.configureTestingModule({\n declarations: [\n HeaderComponent,\n NgxPermissionsRestrictStubDirective\n ],\n providers: providers,\n imports: [\n BrowserAnimationsModule,\n BrowserModule,\n CommonModule,\n CommonSogetrelModule,\n FlexLayoutModule,\n SharedMaterialModule,\n RouterTestingModule.withRoutes([])\n ]\n })\n .compileComponents()\n .then(() => {\n fixture = TestBed.createComponent(HeaderComponent);\n …Run Code Online (Sandbox Code Playgroud) 我有一个多模块项目。每个模块都打包在自己的/ target文件夹中的jar / war文件中。
我想获取每个模块的jar / war文件和一些配置文件,然后将所有内容放入一个zip文件中。
怎么做?我尝试使用Assembly插件,但到目前为止,我所能做的就是将每个模块的zip压缩到各自的/ target文件夹中,因此非常没用^^
我有 2 个高度相同的可滚动 div,我想以两种方式同步它们的滚动。
我在这里做了一个 stackblitz :https://stackblitz.com/edit/angular-9-0-0-rc-1-sync-scroll ?file=src/app/app.component.ts
我看到的是滚动事件反弹了几次,最终滚动速度非常慢,这并不流畅。
我不知道如何防止弹跳,并且当用户在 div 中滚动时,滚动会在另一个 div 中报告,然后事件在那里结束。
我尝试使用 cdkScrollable 但在用户在 div 中滚动的时刻和滚动报告给另一个 div 的时刻之间有一小段时间,我需要它是无缝的。
任何想法?
angular ×7
primeng ×2
typescript ×2
angular-cdk ×1
filereader ×1
jasmine ×1
javascript ×1
maven ×1
mysql ×1
unit-testing ×1