angular - No provider for DecoratorFactory -
i keep getting error message mentioned above , can't find no literature ever provider.
i've been trying call modal in form in order collect return variable , represent in form, return value comes save method
i have feeling error may come having modal component extend component can called open() method in pop-up-service.
the modal:
import { component, oninit, ondestroy } '@angular/core'; import { activatedroute } '@angular/router'; import { response } '@angular/http'; import { observable } 'rxjs/rx'; import { ngbactivemodal, ngbmodalref } '@ng-bootstrap/ng-bootstrap'; import { jhieventmanager, jhialertservice } 'ng-jhipster'; import { publication } './publication.model'; import { publicationpopupservice } './publication-popup.service'; import { publicationservice } './publication.service'; import { publicationtype, publicationtypeservice } '../publication-type'; import {responsewrapper} '../../shared/model/response-wrapper.model'; @component({ selector: 'jhi-publication-dialog', templateurl: './publication-dialog.component.html' }) export class publicationdialogcomponent extends component implements oninit{ title: string; message: string; publication: publication; issaving: boolean; publicationtypes: publicationtype[]; constructor( public activemodal: ngbactivemodal, private alertservice: jhialertservice, private publicationservice: publicationservice, private componentservice: component, private publicationtypeservice: publicationtypeservice, private eventmanager: jhieventmanager ) { super(componentservice); } ngoninit() { this.issaving = false; this.publicationtypeservice.query() .subscribe((res: responsewrapper) => {this.publicationtypes = res.json; }, (res: responsewrapper) => this.onerror(res.json)); } clear() { this.activemodal.dismiss('cancel'); } save() { this.issaving = true; if (this.publication.id !== undefined) { this.subscribetosaveresponse( this.publicationservice.update(this.publication)); } else { this.subscribetosaveresponse( this.publicationservice.create(this.publication)); } return this.publication } private subscribetosaveresponse(result: observable<publication>) { result.subscribe((res: publication) => this.onsavesuccess(res), (res: response) => this.onsaveerror(res)); } private onsavesuccess(result: publication) { this.eventmanager.broadcast({ name: 'publicationlistmodification', content: 'ok'}); this.issaving = false; this.activemodal.dismiss(result); } private onsaveerror(error) { try { error.json(); } catch (exception) { error.message = error.text(); } this.issaving = false; this.onerror(error); } private onerror(error) { this.alertservice.error(error.message, null, null); } trackpublicationtypebyid(index: number, item: publicationtype) { return item.id; } } @component({ selector: 'jhi-publication-popup', template: '' }) export class publicationpopupcomponent implements oninit, ondestroy { routesub: any; constructor( private route: activatedroute, private publicationpopupservice: publicationpopupservice ) {} ngoninit() { this.routesub = this.route.params.subscribe((params) => { if ( params['id'] ) { console.log(params); this.publicationpopupservice .open(publicationdialogcomponent component, params['id']); } else { console.log(params); this.publicationpopupservice .open(publicationdialogcomponent component); } }); } ngondestroy() { var pub = this.routesub; this.route.params.subscribe((params) => { console.log(params); }); this.routesub.unsubscribe(); } } the popup.service:
import { injectable, component } '@angular/core'; import { router } '@angular/router'; import { ngbmodal, ngbmodalref } '@ng-bootstrap/ng-bootstrap'; import { publication } './publication.model'; import { publicationservice } './publication.service'; @injectable() export class publicationpopupservice { private ngbmodalref: ngbmodalref; constructor( private modalservice: ngbmodal, private router: router, private publicationservice: publicationservice ) { this.ngbmodalref = null; } open(component: component, id?: number | any): promise<ngbmodalref> { return new promise<ngbmodalref>((resolve, reject) => { const isopen = this.ngbmodalref !== null; if (isopen) { resolve(this.ngbmodalref); console.log('in isopen '+this.ngbmodalref); } if (id) { this.publicationservice.find(id).subscribe((publication) => { this.ngbmodalref = this.publicationmodalref(component, publication); resolve(this.ngbmodalref); console.log('in if id '+publication); }); } else { // settimeout used workaround getting expressionchangedafterithasbeencheckederror settimeout(() => { this.ngbmodalref = this.publicationmodalref(component, new publication()); resolve(this.ngbmodalref); console.log('in else '+this.ngbmodalref.componentinstance.publication); }, 0); } }); } publicationmodalref(component: component, publication: publication): ngbmodalref { const modalref = this.modalservice.open(component, { size: 'lg', backdrop: 'static'}); console.log(modalref); modalref.componentinstance.publication = publication; modalref.result.then((result) => { this.router.navigate([{ outlets: { popup: null }}], { replaceurl: true }); this.ngbmodalref = null; }, (reason) => { this.router.navigate([{ outlets: { popup: null }}], { replaceurl: true }); this.ngbmodalref = null; }); return modalref; } } the form.module.ts:
import { ngmodule, custom_elements_schema } '@angular/core'; import { routermodule } '@angular/router'; import { drugqualitydatamanagersharedmodule } '../shared'; import {formroute} './form.route'; import {formcomponent} './form.component'; import {formservice} './form.service'; import { nguiautocompletemodule } '@ngui/auto-complete'; import { bootstrapmodalmodule } 'ng2-bootstrap-modal'; import {ngbmodule, ngbactivemodal} "@ng-bootstrap/ng-bootstrap"; import { publicationdialogcomponent, publicationpopupcomponent } "../entities/publication/publication-dialog.component"; const entity_states = [ ...formroute, ]; @ngmodule({ imports: [ drugqualitydatamanagersharedmodule, nguiautocompletemodule, bootstrapmodalmodule, ngbmodule.forroot(), routermodule.forroot(entity_states, { usehash: true }) ], declarations: [ formcomponent, ], entrycomponents: [ formcomponent, ], providers: [ formservice, ngbactivemodal, publicationdialogcomponent, publicationpopupcomponent, ], schemas: [custom_elements_schema] }) export class drugqualitydatamanagerformmodule {} relevant method form:
newpublication() { this.publicationpopupservice.open(this.publicationdialogcomponent).then( (result) => alert('result'), (error) => alert('error'));} and whole form:
import { component, oninit, ondestroy } '@angular/core'; import { activatedroute, router } '@angular/router'; import { subscription } 'rxjs/rx'; import { jhieventmanager, jhiparselinks, jhipaginationutil, jhialertservice } 'ng-jhipster'; import { formservice } './form.service'; import {publication, publicationservice} '../entities/publication' import {country, countryservice} '../entities/country' import {location, locationservice} '../entities/location' import {inndrug, inndrugservice} '../entities/inn-drug' import { items_per_page, principal, responsewrapper } '../shared'; import { paginationconfig } '../blocks/config/uib-pagination.config'; import {formdto} './formdto.model'; import {publicationtype} '../entities/publication-type/publication-type.model'; import {publicationtypeservice} '../entities/publication-type/publication-type.service'; import {publicationdialogcomponent, publicationpopupcomponent } "../entities/publication/publication-dialog.component"; import { dialogservice } "ng2-bootstrap-modal"; import {publicationdrugtypespopuproute} "../entities/publication-drug-types/publication-drug-types.route"; import {publicationpopupservice} "../entities/publication/publication-popup.service"; @component({ selector: 'jhi-form', templateurl: './uploaddata.html' }) export class formcomponent implements oninit, ondestroy { publication: any; issaving: boolean; eventsubscriber: subscription; publicationid; publications: publication[]; countries: country[]; locations: location[]; inndrugs: inndrug[]; formdto: formdto; publicationtypes: publicationtype[]; formdtoloaded = false; dataload = false; publicationdialogcomponent: publicationdialogcomponent; publicationpopupcomponent: publicationpopupcomponent; constructor( private alertservice: jhialertservice, private publicationservice: publicationservice, private publicationpopupservice: publicationpopupservice, private countryservice: countryservice, private locationservice: locationservice, private inndrugservice: inndrugservice, private publicationtypeservice: publicationtypeservice, private formservice: formservice, public dialogservice:dialogservice, private eventmanager: jhieventmanager ) { } ngoninit() { this.registerchangeinform(); this.loadall(); } ngondestroy() { this.eventmanager.destroy(this.eventsubscriber); } loadall() { this.issaving = false; this.publicationservice.queryall().subscribe((res: responsewrapper) => {this.publications = res.json; }, (res: responsewrapper) => this.onerror(res.json)); this.countryservice.query().subscribe((res: responsewrapper) => {this.countries = res.json; }, (res: responsewrapper) => this.onerror(res.json)); this.locationservice.query().subscribe((res: responsewrapper) => {this.locations = res.json; }, (res: responsewrapper) => this.onerror(res.json)); this.inndrugservice.query().subscribe((res: responsewrapper) => {this.inndrugs = res.json; }, (res: responsewrapper) => this.onerror(res.json)); this.publicationtypeservice.query().subscribe((res: responsewrapper) => {this.publicationtypes = res.json; }, (res: responsewrapper) => this.onerror(res.json)); } save() { console.log('save'); } uploadnewdata() { this.dataload = true; this.formdtoloaded = false; this.publicationid = null; } search(publication) { console.log(publication); this.formservice.find(publication.id).subscribe( (result) => (this.formdto = result, this.formdtoloaded = true), (error) => (alert('publication id:' + publication.id + ' not found in database'), this.formdtoloaded = false)); this.loadall(); } registerchangeinform() { this.eventsubscriber = this.eventmanager.subscribe('formlistmodification', (response) => this.loadall()); } trackpublicationtypebyid(index: number, item: publicationtype) { return item.id; } private onerror(error) { this.alertservice.error(error.message, null, null); } newpublication() { this.publicationpopupservice.open(this.publicationdialogcomponent).then( (result) => alert('result'), (error) => alert('error'));} i wouldn't know start in order build plunker this, have encountered same error , won't need @ chunks of code?
Comments
Post a Comment