我正在使用Angular 2开发一个应用程序,我有两个实体:DemandeMedicamentVff
和Medicament
。
我在Accepter
中也有一个名为DemandeMedicamentVff
的按钮,当我点击etat
属性时,我希望它更改为“accptée”,但我也想< / p>
'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);
}
}
这是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的药物上执行功能Accepter,但是如果我在另一种具有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 :(得分:0)
Medicament.quantity = Medicament.quantity -
Demandemedicamentvff.quatite;
属性名称不好,应为quantity
。