2017-03-31 15 views
1

私は現在モーダルフォームを使用していますが、モーダルが開いているときはアイテムの情報をロードしますが、すべての入力をサブミットする場合はnullです これは私のモーダルです "細かい」フォームから入力値を取得しませんAngular2

<div id="modal1" class="modal"> 
    <form #formData='ngForm' (ngSubmit)="onSubmit(formData)"> 
    <div class="modal-content"> 
     <div class="row">  
     <div class="input-field col s6"> 
      <input (ngModel)="productN" value="{{ObjProd.product}}" name="productN" type="text" > 
      <label for="productN">Product Name</label> 
     </div> 
     <div class="input-field col s6"> 
      <input (ngModel)="price" value="{{ObjProd.price}}" name="price" type="text" > 
      <label for="price">price</label> 
     </div> 
     <div class="input-field col s6"> 
      <input (ngModel)="quantity" value="{{ObjProd.quantity}}" name="quantity" type="text" > 
      <label for="quantity">quantity</label> 
     </div> 
     <div class="input-field col s6"> 
      <input (ngModel)="photoURL" value="{{ObjProd.product}}" name="photoURL" type="text" > 
      <label for="photoURL">photoURL</label> 

     </div> 
     <input type="text" placeholder="Full name" value="{{ObjProd.key}}" (ngModel)="namef" name="namef" class="txt" > 
     <input type="text" (ngModel)="keyProduct" name="keyProduct" value="{{ObjProd.key}}" > 
     <input type="text" (ngModel)="typeProduct" name="typeProduct" value="{{ObjProd.type}}" > 
     </div> 
    </div> 
    <div class="modal-footer"> 
     <button type="submit" class="modal-action modal-close waves-effect waves-green btn-flat " >Update Product</button> 
    </div> 
    </form> 
</div> 

、これが私の機能は、これが私のモーダル作品と私のデータ が、出力doesntの仕事 http://imgur.com/a/b2CpI

です

onSubmit(formData) { 
    if(formData.value.typeProduct){ 
     console.log(formData.value.photoURL); 
    }else{ 
     console.log(formData.value.namef, formData.value.photoURL); 
    } 

    } 

を提出しています

+0

あなたの質問を具体的に教えて以下のように別の成分として、モーダル・コンポーネントを使用する必要がありますか? – creimers

+0

ボタンを押したときにformData.value.typeProduct = nullをサブミットし、フォーム内のすべての入力を –

+0

これは私の出力[img](http://imgur.com/a/NanED)です。コンポーネント[img](http://imgur.com/a/P7Oyp) –

答えて

0

コードはindex.htmlにあり、jQueryを使用してアプリケーションを使いこなしています。

代わりに、

import {Component,Input, ViewChild} from '@angular/core'; 
import { ModalDirective } from 'ng2-bootstrap/ng2-bootstrap'; 

@Component({ 
    selector: 'common-modal', 
    template: ` 
    <div bsModal #childModal="bs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"> 
    <div class="modal-dialog modal-sm"> 
    <div class="modal-content"> 
     <div class="modal-header"> 
     <h4 class="modal-title pull-left">{{title}}</h4> 
     <button type="button" class="close pull-right" aria-label="Close" (click)="hideChildModal()"> 
      <span aria-hidden="true">&times;</span> 
     </button> 
     </div> 
     <div class="modal-body"> 
     <form #formData='ngForm' (ngSubmit)="onSubmit(formData)"> 
    <div class="modal-content"> 
     <div class="row">  
     <div class="input-field col s6"> 
      <input [(ngModel)]="productN" value="true" name="productN" type="text" > 
      <label for="productN">Product Name</label> 
     </div> 
     <div class="input-field col s6"> 
      <input [(ngModel)]="price" value="true" name="price" type="text" > 
      <label for="price">price</label> 
     </div> 
     <div class="input-field col s6"> 
      <input [(ngModel)]="quantity" value="true" name="quantity" type="text" > 
      <label for="quantity">quantity</label> 
     </div> 
     <div class="input-field col s6"> 
      <input [(ngModel)]="photoURL" value="true" name="photoURL" type="text" > 
      <label for="photoURL">photoURL</label> 

     </div> 
     <input type="text" placeholder="Full name" value="true" [(ngModel)]="namef" name="namef" class="txt" > 
     <input type="text" [(ngModel)]="keyProduct" name="keyProduct" value="true" > 
     <input type="text" [(ngModel)]="typeProduct" name="typeProduct" value="true" > 
     </div> 
    </div> 
    <div class="modal-footer"> 
     <button type="submit" class="modal-action modal-close waves-effect waves-green btn-flat " >Update Product</button> 
    </div> 
    </form> 
     </div> 

     <div class="modal-footer"> 
     <div class="pull-left"> 
      <button class="btn btn-default" (click)="hide()"> Cancel </button> 
     </div> 
     </div> 
    </div> 
    </div> 
</div> 
    `, 
}) 
export class CommonModalComponent { 
    @ViewChild('childModal') public childModal:ModalDirective; 
    @Input() title?:string; 
    constructor() { 
    } 
    show(){ 
    this.childModal.show(); 
    } 
    hide(){ 
    this.childModal.hide(); 
    } 
    onSubmit(val){ 
    console.log(val); 
    } 
} 

LIVE DEMO

+0

https://github.com/H4isan/GloriaAppsこれは私のレポです。経路は/目録です。あなたは私を誤解してしまいました。私はすべてをインデックスに入れましたが、もちろん、すべてをhtmlに入れることはしませんでした。 –

+0

あなたはまさに顔? – Aravind

+0

私のモーダルを開くと情報が読み込まれますが、投稿したときにモーダルを開くと編集ボタンが表示されます**何も返されません** '(ngModel)'の代わりに –

関連する問題