0

First of all, I am ery new to Angular, so sorry if my question seems strange.

I know how to attach basic directives like ng-click to elements like that:

<button class="test" ng-click="clearOverlays()">Remove</button>

But how can I attach a directive to input box that will be dinamically generated by Django template language ? Django code:

<ul>{{ filter.form.as_ul }}</ul>

The future element will look like that:

<input id="id_property_parent" name="property_parent" type="radio" value="12">

So the ideal variant would be if I would be able to attach ng-change directive to a future element by it's ID ('id_property_parent')

Is it possible to do it with Angular js framework ?

Eimantas
  • 429
  • 1
  • 4
  • 22

1 Answers1

2

Ok it depends on what you are really trying to achieve. I see two different cases, but from what I can tell, yours quite simple to solve. The two cases are :

  • the dynamic piece of html generated by Django is loaded into the DOM via AJAX;
  • the dynamic piece of html is inserted into the full document before the page is sent to the client.

Correct me if I am wrong but I think your case is the second. In that case, the only thing you have to do is to add an attribute (in your case ng-change) to your input. When Angular will parse the document, it will find and compile the ng-change directive without the need to add any other JS code.

So basically, the question you have to ask is more : "how to add custom attribute to Django's form inputs?"

Hope it helps

atomrc
  • 2,543
  • 1
  • 16
  • 20
  • Thank you :) I didnt even think about this approach and was thinking about some complicated Angular way. Adding an attribute to a field via Django was much easier. – Eimantas Aug 18 '14 at 08:17