2

i need help. I have a project and i need duplicate html nodes dynamically. Those nodes have ng-bind and ng-model attributes like this:

<input class="quest_model" type="text" data-ng-model="quest">
<span ng-bind="quest" class="quest_bind"></span>

I can change this attributes whith Jquery like this:

quest.find("span.quest_bind").attr("ng-bind", "quest" + seq);

but, when i press a button to duplicate a node, the magic of angularJS(ng-bind) not happens. anyone can help me?

Luan Luna
  • 31
  • 4

1 Answers1

0

Use a json object

$scope.quest = {
'this': 'some random value',
'that': 'some other value'
}
$scope.seq = 'this'

then all you have to do is reference the json object in your controller

<span ng-bind="quest[seq]" class="quest_bind"></span>

set the ng-model of the input to $scope.seq which will allow you to control what your span element is binded to.

<input class="quest_model" type="text" ng-model="seq">

So if you type "that" in your input box it will bind the span tag to $scope.quest.that, which equals "some random value"

Likewise, if you type "this" in your input box it will bind the span tag to $scope.quest.this, which equals "some other value"

James Freund
  • 473
  • 4
  • 13
  • Adding new data to your quest object will be extremely easy. to add a new entry named "quest1" you would just use $scope.quest.quest1 = "blah blah blah" – James Freund May 02 '16 at 20:22
  • Then if you typed quest1 into your inputbox it would bind "blah blah blah" to your span element – James Freund May 02 '16 at 20:22