在 Angular 5 HttpClient 中,我可以通过这种方式设置 HttpParams()。
const body = new HttpParams()
.set('email', 'test@mail.com')
.set('password', 'pass');
Run Code Online (Sandbox Code Playgroud)
但是当我尝试以这种方式设置 HttpParams() 时。未设置值。
const paramsMap = new Map<any, any>();
paramsMap.set("email", "test@mail.com");
paramsMap.set("password", "pass");
paramsMap.forEach((value: any, key: any) => {
body.set(key, value);
});
Run Code Online (Sandbox Code Playgroud)
为什么它没有设置?我怎样才能以类似的方式做到这一点?
我正在通过导入材料扩展 mde popopver 使用的弹出窗口添加聊天机器人。但是当我尝试聊天或单击弹出框时,弹出框关闭,是否有任何真/假触发器,以防止单击后弹出框关闭?任何帮助表示赞赏。我想在打字稿中实现这一点,而不是 javascript。
这就是说 xyz.component.html这是我到目前为止所做的。当弹出窗口关闭时,我无法在此窗口中聊天,一旦我单击它
<button class="mdc-fab app-fab--absolute"
[mdePopoverTriggerFor]="appPopover"
mdePopoverTriggerOn="click" aria-label="Favorite" mat-fab ><mat-icon>
<span class="mdc-fab__icon material-icons">textsms</span>
</mat-icon></button>
<mde-popover #appPopover="mdePopover" [mdePopoverOverlapTrigger]="false">
Hi this is the chatbot.
</mde-popover>
Run Code Online (Sandbox Code Playgroud) 我在浏览器中处理后退按钮有问题。我有一个自定义模态(只有 html/css,没有引导程序),我想在用户单击后退按钮时显示这个模态。如果用户选择是,浏览器将直接到上一页。当用户选择否时,模态将消失而不是直接到另一个。我尝试使用 candeactive 和 PlatformLocation,但似乎不起作用。单击时我无法将浏览器直接停止到上一页。对此有任何解决方案吗?如果是,请给我一个例子。感谢大家的帮助!
这是我的代码:
文章.component.html
<div class="editor-page">
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<form [formGroup]="articleForm" (ngSubmit)="handleSubmit()">
<div class="form-group">
<input type="text" name="title" class="form-control" placeholder="Article Title" formControlName="title">
</div>
<div class="form-group">
<input type="text" name="body" class="form-control" placeholder="What's this article about?" formControlName="body">
</div>
<div class="form-group">
<textarea name="description" class="form-control" id="" cols="30" rows="10" placeholder="Write your article (in markdown)" formControlName="description"></textarea>
</div>
<div class="form-group">
<input type="text" name="tagList" class="form-control" placeholder="Enter tags" formControlName="tagList">
</div>
<button class="btn btn-md btn-success float-right">Publish Article</button>
</form>
</div>
</div>
</div>
</div>
<div class="modal" *ngIf="isBackClicked"> …Run Code Online (Sandbox Code Playgroud)我正在使用 Rxjs 6处理Angular 6,同时我有一个关于如果响应失败或有异常返回空/空 Observable 的问题,这是我的假设,我的远程 api 将返回一个IOptionResponse对象,它包含一个消息字符串,可以被指示为“成功”或“失败”,它还包含一个模型,它是一个“IOption”对象数组
export interface IOptionResponse {
message: string;
model: IOption[];
}
Run Code Online (Sandbox Code Playgroud)
这是我的服务方法名称,它将返回一个 IOption 数组的 Observable,它是我的远程 API 结果的“模型”
loadIOptionMembersRelationship(): Observable<IOption[]> {
return this.httpClient.get<IOptionResponse>('${environment.apiUrl}/api/member/XXX')
.map(
(response) => {
console.log(response);
// if response.message is success, return IOption[] model
if (response.message == responseMessage.Success) {
return response.model;
}
else {
// return Observable.empty<IOption[]>(); failed
// return new Observable.empty<IOption[]>(); failed
// return new EmptyObservable<IOption[]>(); failed
// return new Observable<IOption[]>.from([]); failed
// Otherwise …Run Code Online (Sandbox Code Playgroud) 我想验证在 onBlur 中填写的输入,我该怎么做。请帮我。
<form class="form-horizontal" role="form" name="form" id="form"
(ngSubmit)="f.form.valid && onSubmit()"
#f="ngForm" novalidate>
<input type="text" class="form-control" placeholder="Social Id"
[ngModel]="generalUserData.socialId" [maxlength]=12 name="socialId" [minlength]=10
(blur)="onBlurMethod($event.target.name, $event.target.value ,generalUserData)"
#socialId="ngModel" [ngClass]="{ 'is-invalid': f.submitted && socialId.invalid }"
pattern="\d{9}(v|V)|\d{12}" required/>
<div *ngIf="f.submitted && socialId.invalid" class="invalid-feedback">
<div *ngIf="socialId?.errors.required">NIC is required</div>
<div *ngIf="socialId?.errors.minlength">NIC must be at least 10 characters long.</div>
<div *ngIf="socialId?.errors.pattern">Not valid NIC</div>
<div *ngIf="socialId?.errors.maxlength">NIC must be less than 12 characters long.</div>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
我使用了下面的示例链接,然后我想在模糊上进行验证,我该怎么做。
我的打字稿代码如下。
selectedAll: any;
selectedAllSecondname: any;
this.name = [ {name: 'as', value: 'as', selected: false },
{name: 'bs', value: 'bs', selected: false },
{name: 'cs', value: 'cs', selected: false } ];
this.Secondname = [ {name: 'dd', value: 'dd', selected: false },
{name: 'ee', value: 'ee', selected: false },
{name: 'ff', value: 'ff', selected: false } ];
this.Thirdname = [ {name: 'gg', value: 'gg', selected: false },
{name: 'hh', value: 'hh', selected: false },
{name: 'ii', value: 'ii', selected: false } ]; …Run Code Online (Sandbox Code Playgroud) 我认为这个问题很清楚。我找不到任何有关如何取消订阅 -rsjx操作的信息,例如interval or timer?
我的组件:
public intervallTimer = interval(5000);
ngOnInit() {
this.getValues();
this.intervallTimer.subscribe(() => this.getValues());
}
// What I like to do is something like this, but "unsubscribe()" that's no function
somefunction(){
this.intervallTimer.unsubscribe()
}
Run Code Online (Sandbox Code Playgroud) 好吧,我又来处理更多的 Angular 问题了。对不起 (?)
问题是我试图在注册后重定向用户,但由于某种原因,我每次都会收到下一个错误:
ERROR TypeError: "this.router is undefined"
Run Code Online (Sandbox Code Playgroud)
基本上,我正在处理表单提交(工作正常)输入并将它们发布到我的 Laravel API,它接受它,执行注册并返回成功消息。无论哪种方式,我都无法使用下一段代码重定向用户(使用 Angular Router):
onSubmit() {
this.authService.registerUser(this.user).subscribe(
response => {
let data = Object.assign(response.alert, this.denyControllConfig);
this.sweetAlert(data);
},
error => {
let data = {};
let errors = error.error.errors;
for (let key in errors) data[key] = errors[key][0];
// this.sweetAlert(data);
}
);
setTimeout(function () {
this.router.navigate(['login']);
}, 2000);
}
Run Code Online (Sandbox Code Playgroud)
我在文件的顶部像这样导入了路由器:
import { Router } from "@angular/router";
Run Code Online (Sandbox Code Playgroud)
这是我的类构造函数:
constructor(
private router: Router,
private authService: AuthService
) { }
Run Code Online (Sandbox Code Playgroud)
有什么问题吗?
我使用 angular 6 的反应形式制作了一个包含电子邮件用户名和头像等字段的表单。我知道我需要表单数据来上传图像,但我不知道如何在 angular 6 的反应形式中使用它。任何人都可以提供帮助?
我有一个非常简单的 http 服务:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from '../../environments/environment';
import { JsOrder } from '../stores/models/order';
@Injectable({
providedIn: 'root'
})
export class OrderService {
private ordersUrl = `${environment.httpApiUrl}/orders`;
constructor(private http: HttpClient) {}
fetchOrders(): Observable<JsOrder[]> {
return this.http.get<JsOrder[]>(this.ordersUrl);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图从@ngrx/effects 调用它(基于网络上的几个示例):
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import …Run Code Online (Sandbox Code Playgroud) angular6 ×10
angular ×3
typescript ×3
angular5 ×1
html ×1
material-ui ×1
ngrx ×1
ngrx-effects ×1
rxjs ×1
rxjs6 ×1