Problem seems that when the you enter in the link function, the html part in the ng-if  doesn't exist, even if the ng-if=true, in the HTML tree then angular add the html if the condition in th ng-if is satisfied.