我正在開發一個Angular 2應用程序,我有兩個實體:DemandeMedicamentVff
和Medicament
。Angular 2,錯誤:'DatePipe'管道'Invalid Date'無效參數
我也有一個在DemandeMedicamentVff
命名Accepter
按鈕,當我點擊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,
) { }
}
第二種模式: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
也許你的'medicamentService.query()。subscribe()'永遠不會解決(因此爲什麼你的數量沒有更新)。 也可能由您的變量命名引起(在嵌套作用域中命名爲'Medicament'的多個變量)。 – Julien
我做了什麼是邏輯,我完全不明白你的意思。如果你想嘗試它,並給我你的答案 –
其實,它可能是一個錯誤的條件:'Medicament.nom == Demandemedicamentvff.medicamentid'。你在比較ID和名字,你確定嗎?它不應該是'Medicament.id == Demandemedicamentvff.medicamentid'嗎? – Julien