本文整理汇总了TypeScript中@angular/http.Headers.append方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Headers.append方法的具体用法?TypeScript Headers.append怎么用?TypeScript Headers.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/http.Headers
的用法示例。
在下文中一共展示了Headers.append方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getLastGame
getLastGame() {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
var data;
this.http.post('../IksOks/php/services/get_active_games_service.php', "what=last", { headers: headers })
.subscribe(
d => data = d,
err => {
console.log(err._body);
},
() => {
//console.log(data._body);
var game = JSON.parse(data._body);
this.newestGameId = game.id;
document.getElementById("active-games").style.color = "#B21212";
document.getElementById("notification").innerHTML = "Nova igra protiv: " + (this.token == game.player1.id ? game.player2.username : game.player1.username);
document.getElementById("notification").style.display = "block";
}
);
}
示例2: fakeAsync
fakeAsync(() => {
// GIVEN
const headers = new Headers();
headers.append('link', 'link;link');
const user = new User(123);
spyOn(service, 'query').and.returnValue(Observable.of({
json: [user],
headers
}));
spyOn(service, 'update').and.returnValue(Observable.of({ status: 200 }));
// WHEN
comp.setActive(user, true);
tick(); // simulate async
// THEN
expect(service.update).toHaveBeenCalledWith(user);
expect(service.query).toHaveBeenCalled();
expect(comp.users[0]).toEqual(jasmine.objectContaining({id: 123}));
})
示例3: addNew
addNew(usercreds) {
var headers = new Headers();
var creds = 'name=' + usercreds.username + '&password=' + usercreds.password;
var emailid = 'name=' + usercreds.username;
headers.append('Content-Type', 'application/X-www-form-urlencoded');
this.http.post('http://localhost:3333/adduser', creds, {headers: headers}).subscribe((data) => {
if(data.json().success) {
this.http.post('http://localhost:3333/sendmail', emailid, {headers: headers}).subscribe((data) => {
if(data.json().success) {
console.log('mail sent');
}
})
}
}
)
}
示例4: updateProfiles
updateProfiles(id, category, value){
console.log("You are updating Profile ID: " + id + " with the new value of " + value + " for your " + category + "!");
let headers = new Headers();
headers.append('Content-Type', 'application/json');
var object = {
"_id": id,
[category]: value
};
console.log("From Profiles.ts: " + object);
this.http.put('http://localhost:8080/api/profiles/' + id, JSON.stringify(object), {headers: headers})
.subscribe(res => {
console.log(res.json());
});
}
示例5: login
public login(requestData: Object = {}): Observable<boolean> | boolean {
let router: Router = this.router;
let obs;
let headers = new Headers();
headers.append('Content-Type', 'application/json');
try {
obs = this.http.post(apiUrl.login,
JSON.stringify(requestData),
{ headers })
.map(this.success)
.catch(this.error);
} catch (err) {
obs = Observable.of(false);
}
return obs
.map(this.success);
}
示例6: deletequalification
deletequalification(applicationid,qualificationid) {
console.log("Inside delete qualification data function");
console.log("Application ID : "+applicationid);
console.log("Experience ID : "+qualificationid);
let header=new Headers();
header.append('x-access-token',localStorage.getItem("token"));
let opts = new RequestOptions({headers:header, params: {_id:applicationid, qualificationid:qualificationid}});
return new Promise((resolve, reject) => {
this.http.delete('/privateapi/qualification',opts)
.map(res => res.json())
.subscribe(res => {
console.log('success');
resolve(res);
}, (err) => {
console.log('failure');
console.log(err);
reject(err);
});
});
}
示例7: get
get(url: string, query: any, oauthKey: OAuthKey, oauthToken: OAuthToken){
let authHeader = new Headers();
authHeader.append('Authorization',this.oauth.createHeaderString('GET',url,query,oauthKey,oauthToken,this.oauth.createNonce(10),this.oauth.createTimestamp()));
let requestUrl = url;
let queryArray:any[] = [];
Object.keys(query).forEach((k)=>{
queryArray.push({
key: this.oauth.fixedEncodeURIComponent(k),
val: this.oauth.fixedEncodeURIComponent(query[k])
});
});
if(queryArray.length > 0){
requestUrl += '?';
requestUrl += queryArray.map((param:any)=>{
return param.key+'='+param.val;
}).join('&');
}
return this.http.get(requestUrl,{headers: authHeader});
}
示例8: onSubmit
onSubmit(value: string): void {
if(this.userForm.valid) {
this.postValue = JSON.stringify(value)
this.postJSON = JSON.parse(this.postValue)
var body = "username=" + this.postJSON.username + "&password=" + this.postJSON.password;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http
.post('http://localhost:3000/api/v1/users/sign_in.json',
body, {
headers: headers
})
.map(response => response.json())
.subscribe(
data => this.res = data
)
console.log(this.res)
}
}
示例9: getListSubjects
getListSubjects(id){
//AGREGAMOS LAS CABECERAS Y PARAMETROS PARA LA CONSULTA
let headers= new Headers();
headers.append('x-session', window.localStorage.getItem('x-session'));
//CREAMOS UNA VARIABLE OBSERVABLE QUE GENERARA LAS NOTIFICACIONES CONSULTANDO EL BACK
var observable = Observable.create( observer => {
// this.http.get(urlRest + 'admin/course/' +id+ '/topics',{ headers: headers})
this.http.get(urlRest + 'admin/course/' + id + '/topics',{ headers: headers})
.subscribe(dat => {
let res = dat.json();
observer.next(res);
observer.complete();
observer.error('Algo esta mal!!');
console.log('*****************');
console.log(observable);
console.log('*****************');
})
});
return observable;
};
示例10: onRegister
onRegister(): void {
var data = "username=" + this.registerForm.value.username + "&password=" + this.registerForm.value.password + "&firstName=" + this.registerForm.value.firstName + "&lastName=" + this.registerForm.value.lastName;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this.http.post('http://localhost/it255-projekat/php/registerservice.php', data, { headers: headers })
.map(res => res)
.subscribe(data => this.postResponse = data,
err => {
var obj = JSON.parse(err._body);
document.getElementsByClassName("alert")[0].style.display = "block";
document.getElementsByClassName("alert")[0].innerHTML = obj.error.split("\\r\\n").join("<br/>").split("\"").join("");
},
() => {
var obj = JSON.parse(this.postResponse._body);
localStorage.setItem('token', obj.token);
alert("Uspesno ste napravili nalog")
this.router.navigate(['./']);
}
);
}