我的代码如下:
密码change.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
我该如何解决?
答案 0 :(得分: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, ...}
//...
}