In my Angular 1.5.8 application, I have created an attribute directive called my-directive
. I am trying to apply this directive to an element while passing two additional parameters - one with one-way binding (@) and the other with two-way binding (=).
Everything functions as expected until I attempt to customize the directive's compile function in order to include extra attributes. While the one-way binding continues to work correctly, the two-way binding seems to disappear.
You can view the issue on this plunk.
Upon commenting out the compile function, everything returns to normal operation. It appears that I may be unintentionally overriding the default behavior, but I am struggling to identify how to prevent this from happening.
This is my current compile function:
compile: function compile(element, attrs) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) {},
post: function postLink(scope, iElement, iAttrs, controller) {
if (!iAttrs.compiled) {
iElement.attr('compiled', true);
iElement.attr('ng-click', "$ctrl.onClick()");
$compile(iElement)(scope);
}
}
};
}