1

我使用 Angular 2 MockBackend 来模拟结果并设置响应取决于方法类型(Post|Get|...)。例如:

if (connection.request.url.endsWith('/api/authenticate') && connection.request.method === RequestMethod.Post) {

但是我在编译时有错误。例如:

[default] ...
Operator '===' cannot be applied to types 'RequestMethod.Post' and 'RequestMethod.Get'.
4

1 回答 1

0

使用typeofandindexOf代替:

connection.request.url.endsWith('/api/authenticate') && [typeof connection.request.method].indexOf(typeof RequestMethod.Post) !== -1 

参考

于 2017-07-03T15:16:33.397 回答