Angular 2,错误:'DatePipe'管道'Invalid Date'无效参数
我正在开发一个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
Medicament.quantity = Medicament.quantity -
Demandemedicamentvff.quatite;
属性的名称是不好的,它应该是quantity
。
不,它写在模型中的quatite –
也许你的'medicamentService.query()。subscribe()'永远不会解决(因此为什么你的数量没有更新)。 也可能由您的变量命名引起(在嵌套作用域中命名为'Medicament'的多个变量)。 – Julien
我做了什么是逻辑,我完全不明白你的意思。如果你想尝试它,并给我你的答案 –
其实,它可能是一个错误的条件:'Medicament.nom == Demandemedicamentvff.medicamentid'。你在比较ID和名字,你确定吗?它不应该是'Medicament.id == Demandemedicamentvff.medicamentid'吗? – Julien