2016-12-25 74 views
-1

我正在通過angular-for-rails-developer書,並且正在'Getting Angular2-令牌註冊用戶'錯誤在[默認] new-user.component.ts:21:4提供的參數不匹配調用目標的任何簽名

我的new-user.component.ts和app.module.ts與本書中的匹配。關於我失蹤的任何想法?

下面的代碼: app.module.ts:

import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 

import { Angular2TokenService } from 'angular2-token'; 

import { HomeLibraryRoutingModule } from './app-routing.module'; 
import { AppComponent } from './app.component'; 
import { NewUserComponent } from './new-user/new-user.component'; 

@NgModule({ 
    declarations: [ 
    AppComponent, 
    NewUserComponent 
    ], 
    imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    HomeLibraryRoutingModule 
    ], 
    providers: [Angular2TokenService], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

新用戶/新user.component.ts

import { Component, OnInit } from '@angular/core'; 
import { Angular2TokenService } from 'angular2-token'; 

@Component({ 
    selector: 'app-new-user', 
    templateUrl: './new-user.component.html', 
    styleUrls: ['./new-user.component.css'] 
}) 
export class NewUserComponent implements OnInit { 

    constructor(private _tokenService: Angular2TokenService) { 
    this._tokenService.init({ 
     registerAccountPath: '/api/auth' 
    }); 
    } 

    ngOnInit() { 
    } 

    register() { 
    this._tokenService.registerAccount(
     '[email protected]', 
     'password', 
     'password' 
    ); 
    } 
} 

在webstorm中,_tokenService init和registerAccount方法被列爲未解決。

+0

它沒有幫助,您可以在這裏添加您的代碼? –

+1

聽起來像是你正在調用太多/很少參數的函數 – adriancarriger

回答

1

試試這個:

register() { 
    this._tokenService.registerAccount({ 
     email: '[email protected]', 
     password: 'password', 
     passwordConfirmation: 'password' 
    }); 
    } 
+0

是的,我會試試這個。它看起來像[registerAccount](https://github.com/neroniaky/angular2-token#registeraccount)的函數簽名自從我編寫該書的一部分(以及我的書需要更新)以來已經發生了變化。 –

+0

謝謝!我盯着https://www.npmjs.com/package/angular2-token#signin,錯過了改變。 – grouchomc

相關問題