我已经更新到Angular 6并且我正在尝试使用ForkJoin,所以在我的服务上我有:
import { forkJoin } from 'rxjs/observable/forkJoin';
Run Code Online (Sandbox Code Playgroud)
但它没有认识到并且我得到了:
...ForkJoin has no exported member
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我有一些代码可以发布一些数据来创建数据记录。
它在服务中:
这是代码:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
create() {
const postedData = { userid: 1, title: 'title here', body: 'body text' };
return this.http.post('https://jsonplaceholder.typicode.com/posts', postedData, httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是...我该怎么做才能从用户登录时获得该网址的要求...我如何传递凭据?
我有一项服务,该服务具有执行某些操作的方法。
service.ts:
doSomething() {
// Does something here
}
Run Code Online (Sandbox Code Playgroud)
该服务与以下组件进行通讯:
myComponent.ts
我有:myComponent.html,其中有一个div:
<div class="myDiv">Something Here</div>
Run Code Online (Sandbox Code Playgroud)
我想要的是通过服务doSomething()方法中的代码显示和隐藏div。
像这样:
doSomething() {
1. Show myDiv
2. // Do something here
3. Hide myDiv
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我正在使用Angular 6 httpClient并在服务中包含以下代码:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'text/xml' })
};
@Injectable({
providedIn: 'root'
})
export class ApiService {
constructor(private http: HttpClient) { }
post() {
const postedData = { userid: 1, title: 'title here', body: 'body text' };
return this.http.post('this url here', postedData, httpOptions).subscribe(result => {
console.log(result);
}, error => console.log('There was an error: '));
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:我想发布一个xml文件,那么我该如何修改此代码呢?