0

I have HTML rect element that i am creating dynamically from the TS file. I want to add text inside the shape, how can i dot it?

current code:

 const toolTipNode = this.createSvgElem('rect', {
                'x': elementPositionX,
                'y': elementPositionY,
                'width': '300',
                'height': '100',
                'class': 'click-tooltip'
            });
            this.renderer.appendChild(this.layoutSvg, toolTipNode); 

[EDIT]

Let say that I create in the same way a text element, How can i add the text inside?

  const text = this.createSvgElem('text', {
                'x': elementPositionX,
                'y': elementPositionY,
                'width': '300',
                'height': '100',
                'class': 'click-tooltip'
            });
Igor.ro
  • 37
  • 2
  • 9
  • just need to create text element and append in rect https://stackoverflow.com/questions/6725288/svg-text-inside-rect – xdeepakv Jun 03 '19 at 11:57
  • @xdeepakv Thanks for the replay. Is it the only option? (I wanted to avoid that) – Igor.ro Jun 03 '19 at 11:58
  • i think this works : ```const text = this.renderer.createText('Hello world!'); this.renderer.appendChild(toolTipNode, text);``` – Fateme Fazli Jun 03 '19 at 11:59
  • This is the way canvas work, u have to draw it. without draw it wont work. u can create util function to simplify it. – xdeepakv Jun 03 '19 at 12:19

0 Answers0