如何在API HTTP hea中修复StaticInjectorError(AppModule)

时间:2018-12-29 17:22:05

标签: rest angularjs-directive angular-ui-router

我正在开发一个简单的待办事项应用程序。我使用LaravelAngular 6作为前端开发了后端。现在我在访问任务时遇到问题。

我正在将令牌值从logincomponent传递给todocomponent。

这是我的代码:

logincomponent.ts

loginUser(event) {

    let param: any = {
        email: this.uname,
        password: this.pswd
        event.preventDefault()
        this.dataService.login(param).subscribe(
            data => {
                this.usertask.task(data);
            }
            // console.log("token gnrtd" + this.usertask.task(data));
        }
    );
}

todocomponent.ts

 task(token) {
     this.http.post(this.dataService.APIList.task, {
         headers: {
             'Authorization': ''
         },
         token
     }).subscribe(data => {
         if (data) {
             console.log("data from todo");
         } else {
             console.log("error on token acess")
         }
     })

 }

我的错误:

  

core.js:14597错误错误:未捕获(按承诺):错误:   StaticInjectorError(AppModule)[LoginComponent-> TodoComponent]:
  StaticInjectorError(平台:核心)[LoginComponent-> TodoComponent]:       NullInjectorError:TodoComponent没有提供者!错误:StaticInjectorError(AppModule)[LoginComponent-> TodoComponent]:
  StaticInjectorError(平台:核心)[LoginComponent-> TodoComponent]:       NullInjectorError:TodoComponent没有提供者!       在NullInjector.push ../ node_modules/@angular/core/fesm5/core.js.NullInjector.get   (core.js:3228)       在resolveToken(core.js:3473)       在tryResolveToken(core.js:3417)       在StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get   (core.js:3314)       在resolveToken(core.js:3473)       在tryResolveToken(core.js:3417)       在StaticInjector.push ../ node_modules/@angular/core/fesm5/core.js.StaticInjector.get   (core.js:3314)       在resolveNgModuleDep(core.js:19784)       在NgModuleRef_.push ../ node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get   (core.js:20473)       在resolveDep(core.js:20844)       在resolvePromise(zone.js:814)       在resolvePromise(zone.js:771)       在zone.js:873       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask   (zone.js:421)       在Object.onInvokeTask(core.js:16147)       在ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask   (zone.js:420)       在Zone.push ../ node_modules / zone.js / dist / zone.js.Zone.runTask(zone.js:188)       在rainMicroTaskQueue(zone.js:595)       在ZoneTask.push ../ node_modules / zone.js / dist / zone.js.ZoneTask.invokeTask中   [作为调用](zone.js:500)       在invokeTask(zone.js:1540)

0 个答案:

没有答案