我已经实现了这样的if语句
if (this.service.check() ) {
return true;
}
else {
}
Run Code Online (Sandbox Code Playgroud)
如果条件等待来自后端的响应.但是在observable执行之前,它会进入else语句并完成条件而不会在开始时检查if条件.
这是我从后端获取数据的可观察方法
public check(){
this.getActorRole().subscribe(
(resp => {
if (resp == true){
return true
}
}),
(error => {
console.log(error);
})
);
}
}
Run Code Online (Sandbox Code Playgroud)
那么如何使条件等待直到它从后端得到响应
我有一个规范代码来测试这样
it('login test', () => {
const fixture = TestBed.createComponent(component);
fixture.detectChanges();
let authService = fixture.debugElement.injector.get(Auth);
spyOn(authService, 'login').and.returnValue('');
const elements = fixture.nativeElement;
fixture.componentInstance.login();
expect(authService.login).toHaveBeenCalled();
});
Run Code Online (Sandbox Code Playgroud)
和这样的实现代码
login() {
this.auth.login(this.username, this.password).subscribe(() => {
}
});
}
Run Code Online (Sandbox Code Playgroud)
它给出了错误:
this.auth.login(...).subscribe不是一个函数
为什么会发生这种错误?
我在表格行中加了一个按钮.但我想分别为他们处理onClick事件.但是当我点击按钮时,表格行点击事件也会被触发.如何仅在单击按钮时仅触发按钮单击元素.这是我目前正在使用的代码
<table class="table" style="width:100%;">
<div *ngFor="let data of Data; let j = index;">
<tr [ngClass]="{onClickMember: data .clicked}" (click)="addData(data , j)">
<td width="15%">{{member.name}}</td>
<td width="15%"><button class="role-toggle" (click)="changeData(data , j)">{{data .role}}</button></td>
</tr>
</div>
</table>
Run Code Online (Sandbox Code Playgroud) 我使用以下代码在地图中创建一个矩形leaflet。
const rectangles = [[51.49, -0.08], [51.5, -0.06]]
<Rectangle key={key} bounds={rectangle} color="green">
</Rectangle>
Run Code Online (Sandbox Code Playgroud)
我想在矩形内添加文本,就像矩形的标签一样,有办法做到这一点吗?
我为此使用了react-leaflet库。
这是CKEditor文档说的配置编辑器的方式http://docs.ckeditor.com/#!/guide/dev_toolbarconcepts-section-toolbar-groups-configuration
我在HTML中使用这样的
<ckeditor
[(ngModel)]="ckeditorContent"
[config]="{toolbar : 'Basic', uiColor: '#FFFFFF'}"
(change)="onChange($event)"
(ready)="onReady($event)"
(focus)="onFocus($event)"
(blur)="onBlur($event)"
debounce="1000"
>
</ckeditor>
Run Code Online (Sandbox Code Playgroud)
那么如何在angular2中将此配置提供给我的CKEditor?
angular ×5
ckeditor ×1
file-upload ×1
leaflet ×1
observable ×1
onclick ×1
reactjs ×1
unit-testing ×1