没有LogService的提供商?

时间:2017-03-17 15:13:00

标签: angular

这是我的logService:

/* * * ./app/comments/components/comment.service.ts * * */
// Imports
import { Injectable }     from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Log }           from '../model/log.model';
import {Observable} from 'rxjs/Rx';

// Import RxJs required methods
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

@Injectable()
export class LogService {
     userData: any;
     private date;
     // Resolve HTTP using the constructor
     constructor (private http: Http) {}

 CheckIn (body): Observable<Log[]> {
         this.date =  new Date();
        //let bodyString = JSON.stringify(body); // Stringify payload
        var bodyString = 'user_email='+body.email +'&checkin='+this.date;

        let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded'});

        let options = new RequestOptions({ headers: headers }); // Create a request option

        return this.http.post('/checkin', bodyString, options) // ...using post request
                         .map(response => { return response.json()}) // ...and calling .json() on the response to return data
                         .catch((error:any) => Observable.throw(error.json().error || 'Server error' )); //...errors if any
    }


}

这是我的日志模块:

import { NgModule }       from '@angular/core';
import { BrowserModule }  from '@angular/platform-browser';
import { FormsModule }    from '@angular/forms';
import { HttpModule, JsonpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import {LogsComponent} from './components/logs.component';
import { LogService } from './services/logService.service';
import { routing } from '../app.routing';

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
     HttpModule,
    JsonpModule,
    routing


  ],
  declarations: [
    LogsComponent
  ],

  providers: [
      LogService
  ],

  exports:[
    LogsComponent
  ]

})
export class LogModule {
}

这是我的日志组件:

import {Component, EventEmitter, Input, OnChanges,OnInit} from '@angular/core';
import {Observable} from 'rxjs/Rx';
import {Router} from '@angular/router';
import { LogService } from '../services/logService.service';
import {User,SharedService} from '../../SharedService'
@Component({
    selector: 'dashboard',
    template: `
    <div class="container">
        <div class="row">
            <div class="col-md-10 col-md-offset-1">
                <div class="panel panel-default">
                    <div class="panel-heading">Dashboard</div>

                    <div class="panel-body">
                        You are logged in! Welcome <span>{{ user.name }} </span>

                    </div>
                    <button *ngIf="checking" type="submit" class="btn btn-primary btn-block" click)="checkout(user.email)">Checkout</button>
                    <button *ngIf="!checking" type="submit" class="btn btn-warning btn-block" (click)="checkin(user.email)">Checkin</button>
                </div>
            </div>
        </div>
    </div>
 `
})
export class LogsComponent {
 private checking = false;
 user:User;
 constructor(
     private logService: LogService,
     private router: Router,
     private ss:SharedService
     ){
        this.user=ss.getUserDetail();
     }

 checkin(values){

   var current = this;
   // Variable to hold a reference of addComment/updateComment
   let logOperation:Observable<any>;
   logOperation = this.logService.CheckIn(values);
   logOperation.subscribe(
     res => {
       if(res.isLoggedIn == true){
         console.log('usao u res',res.user)
         this.ss.setUserDetail(res.user);
          current.router.navigate(['/home']);
       }
      },
     err => { console.log(err) }

  );
  }

}

为什么我会收到此错误的任何建议?

0 个答案:

没有答案