मेसेड किया गया है मेरे पास कोणीय 4 में एक घटक है जिसे तीन बार कहा जाता है। टेम्पलेट मेटाडाटा में मेरे पास इस तरह के कुछ बाइंडिंग के साथ निर्देश के साथ एक div है।एक घटक से बुलाए गए कोणीय 4 निर्देश का एकाधिक उदाहरण इनपुट मान
@import {gServ} from '../gServ.service';
@Component: ({
selector: 'sr-comp',
template: `<div gDirective [cOptions]="dataChart">`
})
export class SGComponent implements OnInit {
@Input('report') public report: IReportInstance;
cOptions:any;
constructor(private gServ: gServ) {
}
ngOnInit(){
this.cOptions = {};
this.cOptions = this.gServ.objectMerge(this.gServ.defaultOpt, this.report.opt);
//this.report.opt is binded to a component when is instantiated.
//this.gServ.objectMerge is a function that merge the two objects
}
}
this.cOptions घटक के प्रत्येक उदाहरण के बदलने के लिए, तो निर्देश में मैं इस है:
import { Directive, ElementRef, HostListener, Input, OnInit } from '@angular/core';
@Directive({
selector: '[gDirective]'
})
export class SGDirective implements OnInit {
public _element: any;
@Input() public cOptions: string;
constructor(public element: ElementRef) {
this._element = this.element.nativeElement;
}
ngOnInit() {
console.log(this.cOptions);
}
}
समस्या यह है कि console.log(this.cOptions);
हमेशा एक ही वस्तु प्रिंट, तब भी जब घटक के साथ cOptions
सेट किया गया है घटक की ngOnInit
विधि में अलग-अलग मान।
क्या आपको कुछ पता है कि क्या गलत है?
मुझे सिमिलर समस्या है। – Marek
क्या आपने अपने घटक 'ngOnInit' में सीधे सेवा का परिणाम' console.log' 'करने का प्रयास किया था। 'this.cOptions = this.gServ.objectMerge (...); console.log (this.cOptions); ' –