angular - Angular2 multiple emitted events from any action on page -
everyone. started learn angular2 time ago , lately i've confronted issue can't understand solve properly.
here component: have cut out excess code simpler
@component({ moduleid: module.id.tostring(), selector: "editor-group", providers: [], template: ` <div class="section-box" > <div *ngfor="let attr of attrlist" > <editor-block [structure]="opts" ></editor-block> </div> </div> ` }) export class editorgroup implements oninit { attrlist: string[]; opts: = csseditordpy[1]; constructor(private editorservice: editorservice, private _contextservice: contextservice) {} ngoninit() { this.attrlist = ['option1']; } }
here have variable "opts" set data check working, transferring child component . so, hard coded case working expected , no magic happens, when i'm trying define structure child component through function, below
@component({ moduleid: module.id.tostring(), selector: "editor-group", providers: [], template: ` <div class="section-box" > <div *ngfor="let attr of attrlist" > <editor-block [structure]="definestructure(attr)" ></editor-block> </div> </div> ` }) export class editorgroup implements oninit { attrlist: string[]; constructor(private editorservice: editorservice, private _contextservice: contextservice) {} ngoninit() { this.attrlist = ['option1']; } definestructure(option: string): editoritem { var item: editoritem; (var i: number = 0; < editordpy.length; i++) { if (editordpy[i].name === option) { item = editordpy[i]; } } return item; } }
i noted started working super slowly, found out definestructure() function executes 500 times in second. firstly thought happens because of rxjs observable, cut off them sure commented components except problem still remains. @ last noted definestructure() execute triggered absolutely mouse event: click, context, move ... when ,for example, moving mouse on document, executes ~200 each 10 pixels. reason function executing mouse event when no data has been updated. i've tried lot, i've run out of ideas, thinking need understand root of reason. please, advice.
Comments
Post a Comment