I have an issue while developing my Angular library : angular-coq.
I'm trying to provide these features :
<div ng-controller="myController">
<form coq-model="team1">
<!-- Inputs will be automatically added to form (wrapped in <p>) -->
</form>
</div>
With myController
that expose in scope team1
, a custom class with 2 attributes : id
, name
.
The CoqModel
directive will append to element a <input coq-model-attribute="...">
for each attribute.
CoqModelAttribute
directive need a CoqModel
as parent to have reference of the current model (here team1
) and will compile as follow:
<div ng-controller="myController">
<form coq-model="team1">
<input type="<attribute_name>" ng-model="team1.<attribute_name>" coq-model-attribute="<attribute_name>"/>
</form>
</div>
Here is the implementation of CoqModel directive and here is the implementation of CoqModelAttribute directive ( too large to paste here )
You will see that I "double-$compile" CoqModel
directive.
If I don't do this, the generated inputs ng-model
will not be binded..
So everything works fine expect that the "double-$compile" cause some issues with ng-click
.
In this case :
<div ng-controller="myController">
<form coq-model="team1">
<input coq-model-attribute="name"/>
<br />
<input type="button" value="click me" ng-click="team1.update()" />
</form>
</div>
Clicking on "click me" will call the method team1.update
2 times..
I've tried a lot of different refactoring, all failed to solve this issue... If one of you is an angular expert, please show me how to fix this :)
Thanks a lot !