角度

2017-05-20 5 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.user.image); 
+0

console.log(this.image); 

から

、それを変更することができます – Moonwalker4z