我最近开始学习 Angular (4),并遵循 Angular.io 的教程。
但现在我正在尝试构建自己的应用程序,但遇到了一些问题。我花了一整天的时间试图解决这个问题,但我失败了。
我正在开发一个目前只有登录和注销功能的身份验证服务。
The login
工作正常,但我不明白logout
上班。似乎打破了toPromise()
call.
const url = `${environment.serviceURL}/api/account/logout`;
const headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded',
'withCredentials':true,
'Authorization': `Bearer ${this.token}`});
let options = new RequestOptions({headers: headers});
let result = this.http.post(
url, options).toPromise().then(/*do something*/);
这在控制台中给出了以下错误:
ERROR Error: Uncaught (in promise): TypeError: v.split is not a function
TypeError: v.split is not a function at http://localhost:4200/vendor.bundle.js:26382:76
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:26382:20
at Map.forEach (native)
at Headers.toJSON (http://localhost:4200/vendor.bundle.js:26380:23)
at Object.stringify (<anonymous>)
at Request.Body.text (http://localhost:4200/vendor.bundle.js:26957:25)
at Request.getBody (http://localhost:4200/vendor.bundle.js:27865:29)
at Observable._subscribe (http://localhost:4200/vendor.bundle.js:27393:37)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:567:25)
at http://localhost:4200/vendor.bundle.js:26382:76
at Array.forEach (native)
at http://localhost:4200/vendor.bundle.js:26382:20
at Map.forEach (native)
at Headers.toJSON (http://localhost:4200/vendor.bundle.js:26380:23)
at Object.stringify (<anonymous>)
at Request.Body.text (http://localhost:4200/vendor.bundle.js:26957:25)
at Request.getBody (http://localhost:4200/vendor.bundle.js:27865:29)
at Observable._subscribe (http://localhost:4200/vendor.bundle.js:27393:37)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:567:25)
at resolvePromise (http://localhost:4200/polyfills.bundle.js:3224:31)
at http://localhost:4200/polyfills.bundle.js:3150:17
at SafeSubscriber._error (http://localhost:4200/vendor.bundle.js:66387:85)
at SafeSubscriber.__tryOrSetError (http://localhost:4200/vendor.bundle.js:16367:16)
at SafeSubscriber.error (http://localhost:4200/vendor.bundle.js:16321:26)
at Subscriber._error (http://localhost:4200/vendor.bundle.js:16248:26)
at Subscriber.error (http://localhost:4200/vendor.bundle.js:16222:18)
at Observable._trySubscribe (http://localhost:4200/vendor.bundle.js:572:18)
at Observable.subscribe (http://localhost:4200/vendor.bundle.js:555:27)
at http://localhost:4200/vendor.bundle.js:66387:15
市长的区别在于(至少我认为)login
返回包含用户信息和logout
不返回任何数据。它只是删除服务中的会话。
我只是想知道请求是否成功,以便我可以采取行动。
我做错了什么或者我应该采取什么不同的措施才能使其正常工作?