我在通用服务器控制台日志上收到以下错误(仅对于SSR并非def get_looking_at(xrot, yrot, xpos, ypos, zpos, blocks, reach):
xrot, yrot = math.radians(xrot), math.radians(yrot)
xform = sin(xrot)*cos(yrot)+xpos
yform = sin(yrot)+ypos
zform = -(cos(xrot)*cos(yrot))+zpos
xforward = xform-xpos >= 0
yforward = yform-ypos >= 0
zforward = zform-zpos >= 0
if xforward:
xset = [floor(x+xpos+.5)+.5 for x in range(reach)]
else:
xset = [floor((-x)+xpos+.5)-.5 for x in range(reach)]
if yforward:
yset = [ceil(y+ypos) for y in range(reach)]
else:
yset = [floor((-y)+ypos) for y in range(reach)]
if zforward:
zset = [floor(z+zpos+.5)+.5 for z in range(reach)]
else:
zset = [floor((-x)+xpos+.5)-.5 for x in range(reach)]
xint = []
yint = []
zint = []
for x in xset:
y = ((yform-ypos)*x)/(xform-xpos)
z = ((zform-zpos)*x)/(xform-xpos)
xint.append((x, y+ypos, z+zpos))
for y in yset:
x = ((xform-xpos)*y)/(yform-ypos)
z = ((zform-zpos)*y)/(yform-ypos)
yint.append((x+xpos, y, z+zpos))
for z in zset:
x = ((xform-xpos)*z)/(zform-zpos)
y = ((yform-ypos)*z)/(zform-zpos)
zint.append((x+xpos,y+ypos,z))
intercepts = dict()
for pos in xint:
intercepts[(pos[0]-xpos)**2+(pos[1]-ypos)**2+(pos[2]-zpos)**2] = (pos[0], pos[1], pos[2], "x")
for pos in yint:
intercepts[(pos[0]-xpos)**2+(pos[1]-ypos)**2+(pos[2]-zpos)**2] = (pos[0], pos[1], pos[2], "y")
for pos in zint:
intercepts[(pos[0]-xpos)**2+(pos[1]-ypos)**2+(pos[2]-zpos)**2] = (pos[0], pos[1], pos[2], "z")
indices = [x for x in intercepts]
indices.sort()
for index in indices:
connection = intercepts[index]
if xforward:
x = floor(connection[0]+.5)
xdir = "e"
else:
x = ceil(connection[0]-.5)
xdir = "w"
if yforward:
y = floor(connection[1])
ydir = "d"
else:
y = floor(connection[1])+1
ydir = "u"
if zforward:
z = ceil(connection[2]-.5)
zdir = "n"
else:
z = floor(connection[2]+.5)
zdir = "s"
print(x,y,z)
try:
if blocks.get_data(x, y, z) != None:
if math.sqrt(index) <= reach:
if connection[3] == "x":
return x, y, z, xdir
if connection[3] == "y":
return x, y, z, ydir
if connection[3] == "z":
return x, y, z, zdir
else:
return
else:
continue
except IndexError:
continue
return
)
错误TypeError:Observable_1.Observable.throw不是函数
这是我的服务设置方式
ng serve
***我正在其他组件中订阅import { Injectable, Injector } from '@angular/core';
import { HttpClient, HttpParams, HttpErrorResponse } from '@angular/common/http';
import { Headers, Response } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { Subject, from } from 'rxjs';
import 'rxjs/add/observable/throw';
@Injectable()
export class BcProductService {
constructor(
private http: HttpClient,
private configsService: ConfigsService,
private injector: Injector
) {}
getProductById(product_id) {
const data = { product_id: product_id };
return this.http.get<any>('/getProductById', { params: data }).catch(err => this.errHandler(err));
}
errHandler(error: HttpErrorResponse) {
console.error(error);
return Observable.throw(error.error || "unknown error");
}
}
。
在整个Internet上,我看到ppl忘记了getProductById()
,但是我知道了,该错误仅在服务器端渲染期间发生。我输入了错误的import 'rxjs/add/observable/throw';
吗?
rxjs 6.3.2 Angular CLI: 6.2.4 节点: 9.2.0 操作系统: darwin x64 角度: 6.1.7 rxjs-compat: ^ 6.3.3
答案 0 :(得分:1)
从RxJS 6开始,您需要使用throwError而不是throw。
import { throwError } from 'rxjs';
errHandler(error: HttpErrorResponse) {
console.error(error);
return Observable.throwError(error.error || "unknown error");
}
Package.json:
"rxjs": "6.3.2",
"rxjs-compat": "6.2.2",
注意:不使用carot(^)符号。删除package.lock.json文件并执行“ npm install”。