我有这个错误超过一天,我不知道为什么。
app.module
import {NgModule} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {AppComponent} from "./app.component";
import {FormsModule} from "@angular/forms";
import {LoginComponent} from "./Login/login";
import {LoginService} from "./Login/login.service";
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent,
LoginComponent],
providers:[LoginService],
bootstrap: [AppComponent]
})
export class AppModule {
}
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: '<login></login>'
})
export class AppComponent {
}
login.model.ts
export class LoginModel{
private userName: string;
private password: string;
constructor(userName: string='', password: string=''){
this.userName = userName;
this.password = password;
}
}
login.ts
import {Component} from '@angular/core';
import {LoginModel} from "./login.model";
import {LoginService} from "./login.service";
@Component({
moduleId: module.id,
selector: 'login',
templateUrl:'./login.html',
styleUrls:['../css/styles.css'],
})
export class LoginComponent{
login:LoginModel = new LoginModel();
constructor(public loginService:LoginService){
}
onSubmit() {
this.loginService.output();
}
login.service
import {Injectable, Inject} from '@angular/core';
import {Http, Response} from '@angular/http';
import {Observable} from 'rxjs/Rx';
@Injectable
export class LoginService {
output(){
console.log("You are in the service output class...");
}
}
目前我只是想让应用程序编译,所以我可以创建路由和服务。这是项目的重点,但我一直在打墙。任何建议将不胜感激。
GitHub链接
答案 0 :(得分:5)
在我的情况下,login.service.ts缺少()
中的Injectable()