Using my custom directive I would like to move the ng-model from root directive to child input element. For some reason the model is not working on child element. Here is the code
Markup:
<span usinglink ng-model="test">
<input type="checkbox" value="test" />
<span>{{test}}</span>
</span>
Directive:
mymodule.directive('usinglink', function($compile){
return{
link : function(scope, element, attrs){
element.children('input').attr('ng-model',element.attr('ng-model'));
}
}
});
This exact thing works when I use compile instead of link. Can anyone tell the reason for this behavior and way i can achieve this behavior using link.
omwmodule.directive('prNgDropdown', function ($compile) {
return {
compile : function (element, attributes) {
var selectElement = element;
if (element.attr("ng-model") != undefined) {
element.attr("ng-init", element.attr("ng-model") + "= '" + element.val() + "'");
}
//'Removing the directive after the logic.as the custom directive is placed on the same element. compile would create an infinit loop
//selectElement.removeAttr("pr-ng-dropdown");
//$compile(selectElement.parent())(scope);
}
}
});
For some reason my ng-init is not updating the model.Can you please explain what was missing.
$compile. I can see ng-model added to input tag. What is you angular version? Mine is 1.3.13