2017-05-20 40 views
0

register.component.ts文件HTML表單低於獲取圖像的名字和年月日從角

import { Component, OnInit } from '@angular/core'; 

@Component({ 
    selector: 'app-register', 
    templateUrl: './register.component.html', 
    styleUrls: ['./register.component.css'] 
}) 
export class RegisterComponent implements OnInit { 
firstName: String; 
lastName: String; 
email: String; 
password: String; 
image: File; 
//location 
city: String; 
country: String; 
dateOfBirth: Date; 
// day:String; 
// month:String; 
// year:String; 
numberOfEventsAttended:String; 
eventId: String; 

    constructor() { } 

    ngOnInit() { 
    } 
onRegisterSubmit(){ 
    const user = { 
     firstName: this.firstName, 
     lastName:this.lastName, 
     email: this.email, 
     password: this.password, 
     image: "", // how to get image name 
     location:{ 
      city: this.city, 
      country: this.country 
     }, 
     dateOfBirth:{ 
     day: "", // how to get day 
     month: "",// how to get month 
     year: ""// how to get year 
     }, 
     eventId: "", 
     numberOfEventsAttended: this.numberOfEventsAttended 
    } 
    console.log(this.image); 
} 
} 

register.component.html

<div class="container"> 
    <h3>Registracija</h3> 
    <form (submit)="onRegisterSubmit()"> 
    <div class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> 
     <input type="text" class="form-control" [(ngModel)]="firstName" name="firstName" placeholder="Ime"> 
    </div> 
    <div class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> 
     <input type="text" class="form-control" [(ngModel)]="lastName" name="lastName" placeholder="Priimek"> 
    </div> 
    <div class="input-group"> 
    <span class="input-group-addon"><i class="glyphicon glyphicon-envelope"></i></span> 
    <input type="email" class="form-control" [(ngModel)]="email" name="email" placeholder="E-mail"> 
    </div> 
    <div class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> 
     <input type="password" class="form-control" [(ngModel)]="password" name="password" placeholder="Geslo"> 
    </div> 
    <div class="input-group"> 
    <label>Dodaj sliko:</label> 
    <input type="file" name="image" [(ngModel)]="image"><br> 
    </div> 
    <div class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span> 
     <input type="text" class="form-control" [(ngModel)]="city" name="city" placeholder="Mesto"> 
    </div> 
    <div class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span> 
     <input type="text" class="form-control" [(ngModel)]="country" name="country" placeholder="Država"> 
    </div> 
    <label>Datum rojstva:</label> 
    <div class="input-group"> 
     <span class="input-group-addon"><i class="glyphicon glyphicon-home"></i></span> 
     <input type="date" [(ngModel)]="dateOfBirth" name="dateOfBirth" class="form-control"> 
    </div> 
    <input class="btn btn-primary" type="submit" value="Registriraj" /> 
    <input class="btn btn-secondary" type="reset" value="Prekliči" /> 
</form> 
</div> 

有人可以幫助我我不不知道如何從窗體獲取上傳的圖像名稱以將其保存到我在register.component.ts中創建的用戶對象。此外,我不知道如何獲取每月和每年的一天,並將其作爲字符串保存在用戶對象的方法onRegisterSubmit()中。

回答

0

你可以改變它,

console.log(this.image); 

console.log(this.user.image); 
+0

的問題是,圖像是未定義 – Moonwalker4z