0

我的代码如下:

密码更改.ts

import { Component, OnInit } from '@angular/core';
import { REACTIVE_FORM_DIRECTIVES, FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Meteor } from 'meteor/meteor';
import { MeteorComponent } from 'angular2-meteor';
import { Router , ROUTER_DIRECTIVES} from '@angular/router';
import { MdCheckbox } from '@angular2-material/checkbox';
import { MD_INPUT_DIRECTIVES } from '@angular2-material/input';
import { MD_BUTTON_DIRECTIVES } from '@angular2-material/button';
import { Accounts } from 'meteor/accounts-base';
import { MD_TOOLBAR_DIRECTIVES } from '@angular2-material/toolbar';

import template from './password-change.component.html';

@Component({
  selector: 'password-change',
  template,
  directives: [REACTIVE_FORM_DIRECTIVES, MdCheckbox, MD_INPUT_DIRECTIVES, MD_BUTTON_DIRECTIVES,MD_TOOLBAR_DIRECTIVES]
})
export class PasswordChangeComponent extends MeteorComponent implements OnInit {
  passwordForm: FormGroup;
  error: string;

  constructor(
    private router: Router,
    private formBuilder: FormBuilder
    ) {
      super();
  }

  ngOnInit() {
    this.passwordForm = this.formBuilder.group({
      oldPassword: ['',Validators.required],
      newPassword: ['', Validators.required],
    });

     this.error = '';
  }

  ChangePassword() {
    if (this.passwordForm.valid) {
      Accounts.changePassword({oldPassword:this.passwordForm.value.oldPassword,newPassowrd:this.passwordForm.value.newPassword,}
      ), (err) => {
        if (err) {
          this.error = err;
        } else {
          this.router.navigate(['/party']);
        }
      };
    }
  }
}

错误提示提供的参数与调用目标不匹配。正在询问 oldPassword:string,而不是输入 oldPassword:any

我该如何解决?

4

1 回答 1

0

您可以尝试将 存储oldPassword在一个类型化的字符串变量中,如下所示:

let tmpOldPassword:string = this.passwordForm.value.oldPassword

然后将其传递给Accounts.changePassword函数:

if (this.passwordForm.valid) {   
     let tmpOldPassword:string = this.passwordForm.value.oldPassword;
     Accounts.changePassword({oldPassword:tmpOldPassword, ...}
     //...
}
于 2016-08-11T11:35:40.603 回答