我不斷收到錯誤SB-聯繫-BS4-角4,加入服務
Error: Unexpected value 'SignupService' declared by the module 'SignupModule'. Please add a @Pipe/@Directive/@Component annotation.
雖然我已經注入的SignupModule 所有的依賴是我的代碼
//SignupModule
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { SignupRoutingModule } from './signup-routing.module';
import { SignupComponent } from './signup.component';
import {SignupService} from './signup.component.service';
@NgModule({
imports: [
CommonModule,
FormsModule,
SignupRoutingModule
],
declarations: [
SignupComponent,
SignupService]
})
export class SignupModule { }
here is the signup.component
import { Component, OnInit } from '@angular/core';
import { routerTransition } from '../router.animations';
import { SignupService } from './signup.component.service';
@Component({
selector: 'app-signup',
templateUrl: './signup.component.html',
styleUrls: ['./signup.component.scss'],
animations: [routerTransition()],
providers:[ SignupService]
})
export class SignupComponent implements OnInit {
user:user;
constructor(signupService:SignupService) {
console.log(signupService.register());
this.user={
firstName:'',
middleName:'',
lastName:'',
gender:'',
email:'',
password:'',
repeatPassword:''
}
}
ngOnInit() { }
signup(){
console.log(this.user);
}
}
interface user{
firstName:string,
middleName:string,
lastName:string,
gender:string,
email:string,
password:string,
repeatPassword:string
}
here is the signup.component.service
export class SignupService{
register(){
console.log('service');
return 'test';
}
}
從app.module.ts的聲明部分刪除SignupService並嘗試.. –
是啊,你說得對,我已經解決了它早些時候:)順便感謝 – vin