2016-09-19 76 views
0

我是一個非常基礎的應用程序。我只是試圖讓一個登錄表單來填充,但我得到沒有別的這個神祕的錯誤去錯誤:無法解析TypeDecorator的所有參數:Angular 2 RC-6

Error: Can't resolve all parameters for TypeDecorator:

main.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 

import { AppModule } from './app.module'; 

platformBrowserDynamic().bootstrapModule(AppModule); 

app.module.ts

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"; 

@NgModule({ 
    imports: [BrowserModule, FormsModule], 

    declarations: [AppComponent, 
     LoginComponent], 

    bootstrap: [AppComponent] 
}) 
export class AppModule { 

} 

app.component.ts

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    template: '<login></login>' 
}) 
export class AppComponent { 

} 

login.ts

@Component({ 
    moduleId: module.id, 
    selector: 'login', 
    templateUrl:'./login.html', 

    providers:[ 
     LoginService 
    ] 
}) 

export class LoginComponent{ 

    login: LoginModel = new LoginModel(); 

    constructor(private loginService:LoginService){ 

    } 

    onSubmit() { 
     this.loginService.output(); 
    } 
} 

loginService.ts

@Injectable 
export class LoginService { 

    output(){ 
     console.log("You are in the service output class...") 
    } 
} 

LoginModel.ts

export class LoginModel{ 

    private userName: string; 
    private password: string; 

    constructor(userName: string='', password: string=''){ 
     this.userName = userName; 
     this.password = password; 
    } 

} 

的login.html

<div> 
    <h2><strong>Login</strong></h2> 

    <form (submit)="onSubmit()" class="form-horizontal"> 

     <div class="form-group"> 
      <label class="col-sm-2 control-label">First Name:</label> 
      <div class="col-sm-10"> 
       <input type="text" name="firstName" [(ngModel)]="login.firstName" placeholder="First name" required="required"> 
      </div> 
     </div> 

     <div class="form-group"> 
      <label class="col-sm-2 control-label">Last Name:</label> 

      <div class="col-sm-10"> 
       <input type="password" name="lastName" [(ngModel)]="login.password" placeholder="password" required="required"> 
      </div> 
     </div> 

     <div class="form-group"> 
      <div class="col-sm-offset-2 col-sm-10"> 
       <button type="submit" class="btn btn-info">Submit</button> 
      </div> 
     </div> 

    </form> 
</div> 

在上述形式我的IDE是也說(submit)這裏是不允許的,[(ngModel)]也是。我不知道我在這裏失去了什麼。

----------------------------- Update 1 --------------- ----------

我補充一點:

@NgModule({ 
    imports: [BrowserModule, FormsModule], 

    declarations: [AppComponent, 
     LoginComponent], 

    providors:[LoginService], <---- Added this 

    bootstrap: [AppComponent] 
}) 
export class AppModule { 

} 

沒有當我這樣做,它只是給了我以下錯誤:

`12:14:14 - File change detected. Starting incremental compilation... 
[0] app/Login/login.service.ts(5,1): error TS1238: Unable to resolve signature of class decorator when called as an expression. 
[0] Supplied parameters do not match any signature of call target. 
[0] app/app.module.ts(14,5): error TS2345: Argument of type '{ imports: typeof BrowserModule[]; declarations: (typeof AppComponent | typeof LoginComponent)[];...' is not assignable to parameter of type 'NgModuleMetadataType'. 
[0] Object literal may only specify known properties, and 'providors' does not exist in type 'NgModuleMetadataType'. 

----- ---------------------- update 2 -------------------------- -

項目i S於GIT

GitHub Link

+0

拼寫錯誤。它應該是'providers:[LoginService]'。 – micronyks

回答

0
import {LoginService} from 'valid path'; 

@NgModule({ 
    imports: [BrowserModule, FormsModule], 

    declarations: [AppComponent,LoginComponent], 

    providers:[LoginService]  //<------added here and remove from login.ts. Don't forget to import LoginService again in login.ts file.   

    bootstrap: [AppComponent] 
}) 
+0

請參閱更新之一 – Drew1208

+0

閱讀我在回答中仔細提及的評論。 – micronyks

+0

錯誤./AppComponent類AppComponent - 內聯模板:0:0原因:沒有提供程序TypeDecorator!' – Drew1208

相關問題