【发布时间】:2019-11-28 05:13:42
【问题描述】:
我整天都在工作。一整天一切正常。
重新启动服务器(ng serve)。现在突然出现很多错误。
我设法修复了大部分,但我被这个卡住了。
这是组件 .ts 文件的主要部分:
import { Component, OnInit } from '@angular/core';
import { HttpService } from '../http.service';
@Component({
selector: 'app-playboard',
templateUrl: './playboard.component.html',
styleUrls: ['./playboard.component.scss']
})
export class PlayboardComponent implements OnInit {
brews: Object;
constructor(private _http: HttpService) { }
ngOnInit() {
this._http.myMethod().subscribe(data => {
this.brews = data;
this.dices = this.brews.myBox;
this.diceSeed = this.brews.boxID;
console.log(this.brews);
});
}
这是 http.service.ts 文件:
import { Injectable } from '@angular/core';
import {HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class HttpService {
constructor(private http: HttpClient) { }
myMethod() {
return this.http.get<Object>('https://localhost:44398/api/boggle');
}
myWordMethod(word) {
var url = 'https://localhost:44398/api/wordpoints/' + word;
return this.http.get<Object>(url);
}
}
它工作了一整天,突然出现这些奇怪的错误。
有谁知道可能出了什么问题?非常感谢!
【问题讨论】:
-
你在 console.log 中得到了什么?
-
在服务的
http.get<Object>类型参数中使用类型而不是Object,或者如果必须使用any。
标签: javascript node.js angular typescript npm