jquery - add directive inside file import svg with angular2 -
i have file svg imported, jquery , add directives:
$(seat).attr("myhighlight",""); this "myhighlight" directive added dinamically using jquery directive is:
import { directive, elementref, input } '@angular/core'; declare var $:any; @directive({ selector: '[myhighlight]' }) export class highlightdirective { constructor(el: elementref) { $(el.nativeelement).css("fill","red"); } } now component use directive
import { component, oninit, viewchild,elementref, afterviewinit } '@angular/core'; import {hero} './hero'; import {heroservice} './hero.service'; declare var $:any; @component({ selector: 'my-heroes', template: <h2 myhighlight>my heroes</h2> <div #contentforsvg> </div> providers:[heroservice], }) export class heroescomponent implements oninit,afterviewinit { @viewchild('contentforsvg') contentforsvg : elementref; constructor(private heroservice:heroservice){} ngoninit(): void { this.getheroes(); $('<div></div>').addclass('plano-map-image').load('/aecid.svg', (index:any,svg:any)=> { $("svg > g").each((row_index:any, g:any)=> { $(g).attr('row-id',row_index); $(g,"> g").children().each((seat_index:any,seat:any)=> { //seat $(seat).attr("myhighlight",""); }); }); }).appendto(this.contentforsvg.nativeelement); } title='tour of heros' name = 'windstorm'; heroes:hero[]; selectedhero: hero; getheroes(): void{ this.heroservice.getheroesslowly().then( heroes=> this.heroes=heroes ); } onselect(hero:hero):void { this.selectedhero= hero; } onculturalmap():void{ } } i add attribute myhighlight tag svg not directive because not exist in template of angular, added after in event oninit how this, if want directive
Comments
Post a Comment