let httpParams = new HttpParams().set('aaa', '111');
httpParams.set('bbb', '222');
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?它只设置'aaa'而不是'bbb'
另外,我有一个对象{aaa:111,bbb:222}如何在不循环的情况下设置所有值?
更新(这似乎工作,但如何避免循环?)
let httpParams = new HttpParams();
Object.keys(data).forEach(function (key) {
httpParams = httpParams.append(key, data[key]);
});
Run Code Online (Sandbox Code Playgroud) 不推荐使用以下ngrx选择.
this.store.select(state => state.academy.academy).subscribe((academy) => {
this.academy = academy;
});
Run Code Online (Sandbox Code Playgroud)
我在store.d.ts找到了这个
@deprecated from 6.1.0. Use the pipeable `select` operator instead.
Run Code Online (Sandbox Code Playgroud)
那么......正确的语法是什么?
我试试
this.store.pipe(select(state => state.academy.academy).subscribe((academy) => {
this.academy = academy;
}))
Run Code Online (Sandbox Code Playgroud)
错误:找不到名称'select'.你是说'onselect'吗?
有没有办法比较2分支(branch1和branch2)与gitkraken?
我想要一个有变化的文件列表
我有一个名为EasyBoxComponent的组件,以及一个带有此viewchild的指令
@ViewChild(EasyBoxComponent) myComponent: EasyBoxComponent;
Run Code Online (Sandbox Code Playgroud)
this.myComponent总是未定义的
我认为这是正确的语法..
我的HTML是
<my-easybox></my-easybox>
<p myEasyBox data-href="URL">My Directive</p>
Run Code Online (Sandbox Code Playgroud)
import { Directive, AfterViewInit, HostListener, ContentChild } from '@angular/core';
import { EasyBoxComponent } from '../_components/easybox.component';
@Directive({
selector: '[myEasyBox]'
})
export class EasyBoxDirective implements AfterViewInit {
@ContentChild(EasyBoxComponent) myComponent: EasyBoxComponent;
@ContentChild(EasyBoxComponent) allMyCustomDirectives;
constructor() {
}
ngAfterViewInit() {
console.log('ViewChild');
console.log(this.myComponent);
}
@HostListener('click', ['$event'])
onClick(e) {
console.log(e);
console.log(e.altKey);
console.log(this.myComponent);
console.log(this.allMyCustomDirectives);
}
}Run Code Online (Sandbox Code Playgroud)
我使用HttpClient并创建此拦截器以添加jwt令牌.每一件工作都很完美,但我的做法很糟糕.我在HttpClient拦截器中使用Http.如果我改变
private http: Http,
Run Code Online (Sandbox Code Playgroud)
至
private http: HttpClient
Run Code Online (Sandbox Code Playgroud)
我得到这个循环错误
Cannot instantiate cyclic dependency! InjectionToken_HTTP_INTERCEPTORS ("[ERROR ->]")
Run Code Online (Sandbox Code Playgroud)
任何想法我怎样才能使它工作?
import {Injectable} from "@angular/core";
import {HttpEvent, HttpHandler, HttpInterceptor} from "@angular/common/http";
import {HttpRequest} from "@angular/common/http";
import {Observable} from "rxjs/Observable";
import {Http} from "@angular/http";
import {SiteService} from "../services/site.service";
import {Router} from "@angular/router";
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(
private http: Http,
private router: Router,
private siteService: SiteService
) {}
refreshToken() {
return this.http.get(this.siteService.apiDomain() + '/api/token?token=' + localStorage.getItem('JWToken'), {})
.map((response: any) => …Run Code Online (Sandbox Code Playgroud) 我有一个组件"课程".我将此组件用于列表.此列表有时是水平的,有些时候是垂直的.我可以在组件内部选择dynamicaly模板文件吗?
@Component({
selector: 'course',
templateUrl: getTemplateFile()
})
Run Code Online (Sandbox Code Playgroud)
这样的东西将是很棒的功能!
我有这个引导标签
<ngb-tabset>
<ngb-tab title="Tab 1">
<ng-template ngbTabContent>
Tab 1
</ng-template>
</ngb-tab>
<ngb-tab title="Tab 2">
<ng-template ngbTabContent>
Tab 2
</ng-template>
</ngb-tab>
</ngb-tabset>
Run Code Online (Sandbox Code Playgroud)
选项卡上的文本颜色为蓝色.我知道如果我创建全局样式,我可以覆盖默认值.但我想从父组件设置标签的样式
我知道我可以设置子组件的样式,但在这种情况下它不起作用(如何从父组件的css文件设置子组件的样式?).有什么建议?
styles: [
`
:host { color: red; }
:host ::ng-deep parent {
color:blue;
}
:host ::ng-deep child{
color:orange;
}
:host ::ng-deep child.class1 {
color:yellow;
}
:host ::ng-deep child.class2{
color:pink;
}
`
],
Run Code Online (Sandbox Code Playgroud) 我在使用Angular的网站上使用基于会话的CSRF。进行HTTP呼叫以要求CSRF令牌是否安全?
例如,如果我将具有有效用户会话的请求发送到了一个名为/ csrf / get的页面,并且该页面打印了原始令牌,那么对于CSRF功能而言,这是否足够安全?如果没有,在保持JSON检索功能的同时,我还能做些什么使其更安全?
这将是所有其他事情之前的第一个api调用,我将其保留在localstorage上,以在每个http调用中使用它
this.editForm = this.fb.group({
step1: this.fb.group({
transport_type_id: ['', [Validators.required]],
flight_code: ['', []],
}),
stops: this.fb.array([
this.initStop() //adds dynamicaly the fields, but I want to watch the whole array
])
});
Run Code Online (Sandbox Code Playgroud)
如果我想为step1.transporter_id"valueChanges",那么这个observable工作正常
this.editForm.controls.step1.get('flight_code').valueChanges.subscribe(data => {});
Run Code Online (Sandbox Code Playgroud)
如果我想"观察""stops:this.fb.array",语法是什么?
不起作用的例子
this.editForm.controls.stops.get().valueChanges.subscribe(data => {});
this.editForm.controls.stops.get('stops').valueChanges.subscribe(data => {});
this.editForm.get('stops').valueChanges.subscribe(data => {});
Run Code Online (Sandbox Code Playgroud) 如何将以下订阅合并为一个?
this.form.get("type").valueChanges.subscribe(() => {
this.calcFinalTransports();
})
this.form.get("departure").valueChanges.subscribe(() => {
this.calcFinalTransports();
})
this.form.get("destination").valueChanges.subscribe(() => {
this.calcFinalTransports();
})
this.form.get("stations").valueChanges.subscribe(() => {
this.calcFinalTransports();
})
Run Code Online (Sandbox Code Playgroud) angular ×7
angular-http ×1
api ×1
csrf ×1
git ×1
gitkraken ×1
http ×1
javascript ×1
ng-bootstrap ×1
ngrx ×1
observable ×1
rxjs ×1