嗨,我是ionic的新手,我已经使用ionic构建了一个应用程序,当我在PC上进行编译时它已经运行了,当我尝试使用ionic cordova运行android来运行该应用程序时,它显示了错误,我发现我正在使用的所有变量都是错误,我也无法构建该应用程序。所以请有人帮我解决这个问题 先谢谢q 这是我得到的错误
[12:00:54] typescript: src/pages/find-genie4/find-genie4.ts, line: 31
Argument of type '{ headers: { 'Authorization': string; }; }' is not assignable to parameter of type
'RequestOptionsArgs'. Types of property 'headers' are incompatible. Type '{ 'Authorization': string; }' is
not assignable to type 'Headers'. Object literal may only specify known properties, and ''Authorization''
does not exist in type 'Headers'.
L30: const token = JSON.parse(localStorage.getItem("userData"));
L31: this.http.get('https://api.findgenie.org/v1/my-requests/',{headers: {'Authorization': 'Token '+token.token}}
L32: this.posts = data.json().data.user_requests;
[12:00:54] typescript: src/pages/find-genie4/find-genie4.ts, line: 32
Property 'posts' does not exist on type 'FindGenie4Page'.
L31: this.http.get('https://api.findgenie.org/v1/my-requests/',{headers: {'Authorization': 'Token '+token.token}}).subscribe(data => {
L32: this.posts = data.json().data.user_requests;
L33: this.rating = data.json().data.user_details.rating;
[12:00:54] typescript: src/pages/find-genie4/find-genie4.ts, line: 33
Property 'rating' does not exist on type 'FindGenie4Page'.
L32: this.posts = data.json().data.user_requests;
L33: this.rating = data.json().data.user_details.rating;
L34: console.log("this.posts",this.posts)
[12:00:54] typescript: src/pages/find-genie4/find-genie4.ts, line: 34
Property 'posts' does not exist on type 'FindGenie4Page'.
L33: this.rating = data.json().data.user_details.rating;
L34: console.log("this.posts",this.posts)
L35: });
答案 0 :(得分:0)
您应该像这样附加标头,使用HttpHeaders
类发送标头。在您的响应数据中,将其类型声明为any
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Token '+token.token
})
};
this.http.get('https://api.findgenie.org/v1/my-requests/',httpOptions ).subscribe((data: any) => {
this.posts = data.json().data.user_requests;
this.rating = data.json().data.user_details.rating;
});