0

私はAngular 2でアプリケーションを開発していますが、DemandeMedicamentVffMedicamentの2つのエンティティがあります。Angular 2、Error:パイプ 'DatePipe'の無効な引数 'Invalid Date'

は私もDemandeMedicamentVffAccepterという名前のボタンを持って、私はetat属性をクリックしたとき、私はそれが「accptée」に変更を取得したいが、私がした後、私はまた

'Medicament.nom== DemandeMedicament.medicamentid && demandeMedicament.etat= 'Acceptée' {Medicament.quantity = Medicament.quantity-DemandeMedicament.quantity'}'

をしたいです値etatは変更されますが、quantityは変更されません。

それらは私のモデルです:

まずモデル

export class DemandeMedicamentVff { 
    constructor(
     public id?: string, 
     public medicamentid?: string, 
     public date?: any, 
     public quantity?: number, 
     public etat?: number, 
     public signature?: string, 
    ) { } 
} 

第2のモデル:Medicament

export class Medicament { 
    constructor(
     public id?: string, 
     public nom?: string, 
     public type?: string, 
     public quantity?: number, 
     public ref?: string, 
     public datevalidite?: any, 
     public dateproduction?: any, 
    ) { } 
} 

マイコンポーネント

import { Component, OnInit, OnDestroy } from '@angular/core'; 
import { Response } from '@angular/http'; 
import { ActivatedRoute, Router } from '@angular/router'; 
import { Subscription } from 'rxjs/Rx'; 
import { EventManager, ParseLinks, PaginationUtil, JhiLanguageService, AlertService } from 'ng-jhipster'; 
import { Demandemedicamentvff } from './demandemedicamentvff.model'; 
import { DemandemedicamentvffService } from './demandemedicamentvff.service'; 
import { ITEMS_PER_PAGE, Principal } from '../../shared'; 
import { PaginationConfig } from '../../blocks/config/uib-pagination.config'; 
import { MedicamentService } from '../medicament/medicament.service'; 
import { Medicament } from '../medicament/medicament.model'; 
@Component({ 
    selector: 'jhi-demandemedicamentvff', 
    templateUrl: './demandemedicamentvff.component.html' 
}) 
export class DemandemedicamentvffComponent implements OnInit, OnDestroy { 
    currentAccount: any; 
    demandemedicamentvffs: Demandemedicamentvff[]; 
    error: any; 
    medicaments : Medicament []; 
    success: any; 
    eventSubscriber: Subscription; 
    routeData: any; 
    links: any; 
    totalItems: any; 
    queryCount: any; 
    itemsPerPage: any; 
    page: any; 
    predicate: any; 
    previousPage: any; 
    reverse: any; 
    isSaving: boolean; 

    constructor(
     private jhiLanguageService: JhiLanguageService, 
     private demandemedicamentvffService: DemandemedicamentvffService, 
     private medicamentService :MedicamentService, 
     private parseLinks: ParseLinks, 
     private alertService: AlertService, 
     private principal: Principal, 
     private activatedRoute: ActivatedRoute, 
     private router: Router, 
     private eventManager: EventManager, 
     private paginationUtil: PaginationUtil, 
     private paginationConfig: PaginationConfig 
    ) { 
     this.itemsPerPage = ITEMS_PER_PAGE; 
     this.routeData = this.activatedRoute.data.subscribe(data => { 
      this.page = data['pagingParams'].page; 
      this.previousPage = data['pagingParams'].page; 
      this.reverse = data['pagingParams'].ascending; 
      this.predicate = data['pagingParams'].predicate; 
     }); 

     this.jhiLanguageService.setLocations(['demandemedicamentvff']); 
    } 

    loadAll() { 
     this.demandemedicamentvffService.query({ 
      page: this.page - 1, 
      size: this.itemsPerPage, 
      sort: this.sort()}).subscribe(
      (res: Response) => this.onSuccess(res.json(), res.headers), 
      (res: Response) => this.onError(res.json()) 
     ); 
    } 

    loadPage (page: number) { 
     if (page !== this.previousPage) { 
      this.previousPage = page; 
      this.transition(); 
     } 
    } 

    transition() { 
     this.router.navigate(['/demandemedicamentvff'], {queryParams: 
      { 
       page: this.page, 
       size: this.itemsPerPage, 
       sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc') 
      } 
     }); 
     this.loadAll(); 
    } 

    clear() { 
     this.page = 0; 
     this.router.navigate(['/demandemedicamentvff', { 
      page: this.page, 
      sort: this.predicate + ',' + (this.reverse ? 'asc' : 'desc') 
     }]); 
     this.loadAll(); 
    } 

    Accepter(Demandemedicamentvff,Medicament){ 
     this.medicamentService.query().subscribe((res: Response) => { 
      this.medicaments = res.json(); 
      this.medicaments.forEach((Medicament,index)=> 
      { 
       if (Medicament.nom== Demandemedicamentvff.medicamentid && Demandemedicamentvff.etat=="Acceptée") 
       { 
        Medicament.quantity = Medicament.quantity - Demandemedicamentvff.quatite; 
        this.medicamentService.update(Medicament).subscribe((res: Medicament) => 
         this.onSaveSuccess(res), 
         (res: Response) => this.onError(res.json())); 
        } 
       }) 
      }, 

      (res: Response) => this.onError(res.json()) 
     ); 
     Demandemedicamentvff.etat="Acceptée"; 

     this.demandemedicamentvffService.update(Demandemedicamentvff).subscribe((res: Demandemedicamentvff) => 
      this.onSaveSuccess(res), 
      (res: Response) => this.onError(res.json())); 
    } 

    private onSaveSuccess (result: Demandemedicamentvff) { 
     this.eventManager.broadcast({ name: 'demandeModification', content: 'OK'}); 
     this.isSaving = false; 
    } 

    Refuser(Demandemedicamentvff){ 
     Demandemedicamentvff.etat="Refusée"; 
     this.demandemedicamentvffService.update(Demandemedicamentvff).subscribe((res: Demandemedicamentvff) => this.onSaveSuccess(res), 
      (res: Response) => this.onError(res.json())); 
    } 

    ngOnInit() { 
     this.loadAll(); 
     this.principal.identity().then((account) => { 
      this.currentAccount = account; 
     }); 
     this.registerChangeInDemandemedicamentvffs(); 
    } 

    ngOnDestroy() { 
     this.eventManager.destroy(this.eventSubscriber); 
    } 

    trackId (index: number, item: Demandemedicamentvff) { 
     return item.id; 
    } 

    registerChangeInDemandemedicamentvffs() { 
     this.eventSubscriber = this.eventManager.subscribe('demandemedicamentvffListModification', 
     (response) => this.loadAll()); 
    } 

    sort() { 
     let result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')]; 
     if (this.predicate !== 'id') { 
      result.push('id'); 
     } 

     return result; 
    } 

    private onSuccess (data, headers) { 
     this.links = this.parseLinks.parse(headers.get('link')); 
     this.totalItems = headers.get('X-Total-Count'); 
     this.queryCount = this.totalItems; 
     // this.page = pagingParams.page; 
     this.demandemedicamentvffs = data; 
    } 

    private onError (error) { 
     this.alertService.error(error.message, null, null); 
    } 
} 

これはfunctiですmedicament.service.tsでの更新に:

update(medicament: Medicament): Observable<Medicament> { 
    let copy: Medicament = Object.assign({}, medicament); 
    copy.datevalidite = this.dateUtils 
     .convertLocalDateToServer(medicament.datevalidite); 
    copy.dateproduction = this.dateUtils 
     .convertLocalDateToServer(medicament.dateproduction); 
    return this.http.put(this.resourceUrl, copy).map((res: Response) => { 
     return res.json(); 
    }); 
} 

私はdateproductionとdatavaliditeを持っていますが、私はdatevaliditeとdateproductionを持つ別の薬剤にそれをしなかった場合、私はこれを持っていない医薬品に機能アクセプタをした場合は、すべてが良い作品エラー:属性の名前が良くない

> Error: Invalid argument 'Invalid Date' for pipe 'DatePipe' 
at InvalidPipeArgumentError.ZoneAwareError (polyfills.bundle.js:10191) 
at InvalidPipeArgumentError.BaseError [as constructor] 
(vendor.dll.js:86902) 
at new InvalidPipeArgumentError (vendor.dll.js:8772) 
at DatePipe.transform (vendor.dll.js:87676) 
at DateUtils.convertLocalDateToServer (vendor.dll.js:104410) 
at MedicamentService.webpackJsonp../src/main/webapp/app/entities 

/medicament/medicament.service.ts.MedicamentService.update 

(main.bundle.js:65941) 
at SafeSubscriber._next (main.bundle.js:55972) 
at SafeSubscriber.__tryOrUnsub (vendor.dll.js:588) 
at SafeSubscriber.next (vendor.dll.js:537) 
at Subscriber._next (vendor.dll.js:490) 
at Subscriber.next (vendor.dll.js:454) 
at MapSubscriber._next (vendor.dll.js:12416) 
at MapSubscriber.Subscriber.next (vendor.dll.js:454) 
at CatchSubscriber.Subscriber._next (vendor.dll.js:490) 
at CatchSubscriber.Subscriber.next (vendor.dll.js:454) 
ErrorHandler.handleError @ vendor.dll.js:60866 
vendor.dll.js:592 Uncaught InvalidPipeArgumentError 
+0

あなたの 'medicamentService.query()。subscribe()'は決して解決しないかもしれません(なぜあなたの数量が更新されないのか)。 変数ネーミング(ネストされたスコープで 'Medicament'という名前の複数の変数)によっても発生する可能性があります。 – Julien

+0

私は論理が何であったか、あなたが正確に何を意味するのか分からなかった。もしあなたがそれを試して、私に答えを与えることを望むならば –

+0

実際には、それは間違った状態である可能性があります: 'Medicament.nom == Demandemedicamentvff.medicamentid'。あなたはIDと名前を比較していますが、これについては確かですか?それは 'Medicament.id == Demandemedicamentvff.medicamentid'ではありませんか? – Julien

答えて

0
Medicament.quantity = Medicament.quantity - 

    Demandemedicamentvff.quatite; 

、それはquantityする必要があります。

+0

モデルにはquatiteは書かれていません –

関連する問題