使用下面的代码块,
let ob = of(1,2,3);
ob.subscribe((v)=>{
console.log(v)
})
console.log("end")
Run Code Online (Sandbox Code Playgroud)
这些值是同步发出的。subscribe 中的函数是否保证在 print 之前执行end?所以输出将永远是。
1
2
3
end
Run Code Online (Sandbox Code Playgroud) 如何验证mat-chip已将添加到中mat-chip-list。我正在使用ReactiveForms。我已经尝试过required验证器。
该值可以是名称列表,因此在提交表单之前,我需要确保名称列表中至少有1个名称。如果列表为空,mat-error则应显示错误消息。使用required验证器会使表单无效,而不管在列表中添加名称如何。
编辑:反应形式
我试图做一个自定义验证器,现在使用的是反应式表单,而不是模板驱动的表单,但是我无法使它正常工作。我编辑了以下代码以反映我的更改,并创建了此https://stackblitz.com/edit/angular-4d5vfj
的HTML
<form [formGroup]="myForm">
<mat-form-field class="example-chip-list">
<mat-chip-list #chipList formArrayName="names">
<mat-chip *ngFor="let name of myForm.get('names').controls; let i=index;"
[formGroupName]="i"
[selectable]="selectable"
[removable]="removable"
(removed)="remove(myForm, i)">
<mat-icon matChipRemove *ngIf="removable">cancel</mat-icon>
</mat-chip>
<input placeholder="Names"
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
[matChipInputAddOnBlur]="addOnBlur"
(matChipInputTokenEnd)="add($event, asset)">
</mat-chip-list>
<mat-error>Atleast 1 name need to be added</mat-error>
</mat-form-field>
</form>
Run Code Online (Sandbox Code Playgroud)
TS
import {COMMA, ENTER} from '@angular/cdk/keycodes';
import {Component} from '@angular/core';
import {FormGroup, FormControl, FormBuilder, FormArray} from '@angular/forms';
import {MatChipInputEvent} from '@angular/material';
@Component({
selector: 'chip-list-validation-example', …Run Code Online (Sandbox Code Playgroud) angular2-forms angular-material2 angular angular-reactive-forms
我对 angular 8 技术非常陌生,并且在设置默认选中的单选按钮之一时遇到了一些问题。
我尝试添加其中一些属性,[checked]="true", checked但问题仍然存在。
HTML
<div class="form-check">
<mat-radio-button type="radio" id="materialUnchecked" name="filterType"
value="0" [(ngModel)]="filterType" [checked]="true">
By client
</mat-radio-button>
<mat-radio-button type="radio" id="materialChecked" name="filterType"
value="1" [(ngModel)]="filterType">
By student
</mat-radio-button>
<br><br>
</div>
Run Code Online (Sandbox Code Playgroud)
TS
protected filterType;
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激。谢谢
我是 Angular 和 rxjs 的新手,我有以下场景,在该场景中,我需要在成功解析对 api 的调用后进行新的调用,在 Angular / rxjs 的上下文中我不知道该怎么做它
handler(): void {
this.serviceNAme
.createDirectory(this.path)
.pipe(
finalize(() => {
this.someProperty = false;
})
)
.subscribe(
(data) => console.log(data),
(error) => console.error(error.message)
);
}
Run Code Online (Sandbox Code Playgroud)
当上一个 api 成功调用时,重新调用 api 的正确方法是什么?
以下是测试班
@RunWith(MockitoJUnitRunner.class)
public class AuditServiceClientTest {
private MockMvc mockMvc;
@Mock
private RestTemplate restTemplate;
@Mock
AuditServiceClient auditServiceClient;
@Mock
ICommonDataService iCommonDataService;
private AuditServiceResponse auditServiceResponse;
private AuditServiceLog auditServiceLog;
private HttpEntity<AuditServiceLog> request;
@Before
public void setUp() throws Exception {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("X-AGS-Client-Name", "test");
headers.add("X-AGS-Group-Name", "test");
headers.add("Content-Type", "application/json");
auditServiceClient = new AuditServiceClientImpl();
iCommonDataService = new CommonDataService();
auditServiceLog = new AuditServiceLog();
request = new HttpEntity<AuditServiceLog>(auditServiceLog, headers);
auditServiceResponse = new AuditServiceResponse();
auditServiceResponse.setStatus(String.valueOf(200));
auditServiceResponse.setTimestamp("1990-01-01 00:00:01");
auditServiceResponse.setDescription("Description");
Mockito.when(restTemplate.postForObject(Mockito.anyString(), any(HttpEntity.class), ArgumentMatchers.eq(AuditServiceResponse.class)))
.thenReturn(auditServiceResponse);
String a = …Run Code Online (Sandbox Code Playgroud)