#How to increase number dynamically - DrawFlow Library

16 messages · Page 1 of 1 (latest)

sullen bronze
#

Hi there,
In this project, I use DrawFlow library to create nodes.

in the const newNodeId = this.editor.addNode( name,2,1... The number 2 which is hardcoded, it's basically an input.

What I am trying to do, is increase the number (2) using a dedicated function addInputPin(), at the moment there is an alert only, that works.

Could anybody help me to do this?

#
            const newNodeId = this.editor.addNode(
                name,
                1, // *** I need to increase this Number 
                1, // Number of outputs
                pos_x,
                pos_y,
                'Node',
                { category: 'node' },
                nodeHtml
            );
timber wigeon
#
private someNumber = 1;
// ...
              const nextNumber = this.someNumber;
              this.someNumber++;
              const newNodeId = this.editor.addNode(
                name,
                nextNumber,
                1, // Number of outputs
                pos_x,
                pos_y,
                'Node',
                { category: 'node' },
                nodeHtml
            );
sullen bronze
#

What about the method addInputPin() ? - May i ask you to explain the logic ? Thank you for the help

timber wigeon
#

What about it? I don't understand what you're asking.
The logic: you create a property (someNumber) in the object storing the next number. And you increment it every time you want to do it.

sullen bronze
#

When clicking the icon "add-pin" should increment the number - to doing this I've created hte method addInputPin()

#

this is the HTML ```
<div class="add-pin-container" id="add-pin-${nodeId}" style="text-align: center; cursor: pointer;">
<img src="assets/icons/add-pin.svg" class="add-pin-icon" alt="Add Pin" style="width: 20px; height: 20px;" />
</div>

timber wigeon
#

Well, in the addInputPin method, do this.someNumber++.

#

But you're really not using Angular as it's meant to be used.

sullen bronze
#

Yes! In working on somebody else code 😦

#

which approach do you suggest?

#

I am trying to learn as much as possibile

timber wigeon
#

Well, reading the documentation or a good book, and use Angular as it's documented, with HTML in the templates, data binding, event binding.

sullen bronze
#

Correct! They asked me to work on this but can't really change the way it's made.

#

It supposed to be made differently

#

I get you feedback and I will try to refactor the code