I have the following problem:
It turns out that I want to show a <user></user>
directive with Angular and load the policy code into it via a templateURL
. But this directive has to be shown when you click on a button or div
through a ng-click
. I give you an example that I did to test if I could load it. The directive works well if I directly charge but do not do it dynamically.
The code HTML
of the part where it would have to be loaded is:
<div ng-click="showTag()">Click me</div>
<div id="loquesea">
</div>
</div>
And the Angular code that I generated is the following:
angular
.module("plantillas_app",[])
.controller("plantillas_ctrl",controlTemplates)
.directive('usuario',templates);
function templates () {
console.log("Cargando template...");
return{
restrict:'AE',
templateUrl:'template1.html',
scope:{
idCliente:"=persona"
}
};
}
function controlTemplates ($scope,$http){
$scope.usuario1= {nombre:"Juan",apellidos:'Perez Gomez',edad:'32'}
$scope.usuario2= {nombre:"Pedro",apellidos:'Jimenez Gomez',edad:'33'}
$scope.showTag = function () {
console.log("Cargando contenido");
$("#loquesea").html("<usuario persona='usuario1'></usuario><usuario persona='usuario2'></usuario>");
}
}
Can someone tell me or explain why this is happening?