我尝试用angular2创建用户注册,但我不明白为什么会出问题。
启动angular2的错误是以下错误。
A function whose declared type is neither 'void' nor 'any' must return a value.
所以我有以下代码
在组件中
import { Component, OnInit } from '@angular/core';
import { User} from '../../usuarios/signup/user';
import { Router , ActivatedRoute } from '@angular/router';
import { SignUpService } from '../../usuarios/signup/signup.service';
@Component({
selector: 'app-form',
templateUrl: './signup.component.html'
})
export class SignUpComponent implements OnInit {
usuario: User = new User()
constructor(private signUpService:SignUpService,private router:Router , private activatedRoute:ActivatedRoute) {}
ngOnInit() {
}
userRegistration(): void {
this.signUpService.userRegistration(this.usuario);
}
}
和服务
import { Injectable } from '@angular/core';
import { User } from '../../usuarios/signup/user';
import { HttpClient,HttpHeaders} from '@angular/common/http';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable({
providedIn: 'root'
})
export class SignUpService {
private urlEndpoint:string = 'http://localhost:8584/api/public/v1/countries';
private httpHeaders = new HttpHeaders ({'Content-type':'application/json'});
constructor(private http:HttpClient){}
userRegistration(user:User){
this.http.post(this.urlEndpoint,user,{headers:this.httpHeaders});
}
}
用户模型
现在,此请愿书正在与Postman合作。