提交错误中的角度2 on self.context.onSubmit不是函数 [英] angular 2 on from submit error self.context.onSubmit is not a function

查看:92
本文介绍了提交错误中的角度2 on self.context.onSubmit不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的angular 2应用程序中使用2.0.0-rc.6. 在表单提交时出现此错误- self.context.onSubmit不是函数

I am using 2.0.0-rc.6 in my angular 2 application. on form submit I am getting this error - self.context.onSubmit is not a function

它也在浏览器中附加表单值.

also it is appending form values in browser.

http://localhost:3000/register

提交页面重新加载后,URL变成这样.

on submit the page reloading and url become like this.

http://localhost: 3000/register?firstName = vcvvc& lastName = vcv& userName = cvv& password = vcv& password = vcv

代码是

表格

<form class="ui form" (ngSubmit)="onSubmit()" #registrationForm="ngForm">
----
----
 <button type="submit" class="ui button"> Register</button>
    </form>

服务

import { Component } from '@angular/core';
import { User } from '../models/user';
import { RegisterService } from '../services/register.service';

@Component({
    selector: 'side-panel',
    templateUrl: 'app/components/register.component.html'
})
export class RegisterComponent { 

    newuser: User = new User();
    theText: string;

    constructor(private _registerService: RegisterService){ 
    }

    onsubmit(){
        console.log('form submit clicked..');
        this._registerService.sendUser(this.newuser).subscribe(
            date =>{
                this.newuser = new User();
            },
            error => console.log(error)
        );
    }
}

推荐答案

当在事件中调用的方法名称与模板声明不匹配且在类内部时发生此错误

This error occurs when the name of the methods called in an event not matched with the template declaration and inside the class

在模板中,您已将 onSubmit()指定为驼峰式情况

In your template you have specified onSubmit() as camel case

<form class="ui form" (ngSubmit)="**onSubmit()**" #registrationForm="ngForm">

但在班级中,它不是驼峰式案例" onsubmit()"

but inside the class, its not a camelCase "onsubmit()"

 onsubmit(){
        console.log('form submit clicked..');
        this._registerService.sendUser(this.newuser).subscribe(

这篇关于提交错误中的角度2 on self.context.onSubmit不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆