I need to select a template based on a date. I saw a good example . But in this example, the patterns are so simple that he could use strings. In my case, I want to use php to create templates, so I used it like this:
eng.directive('vis', function ($compile) { var getTemplate = function(ir) { var k = (ir.visits.last && parseInt(ir.visits.last.done))?'V':'E'; var s = (ir.data.kind == 0)?'H':'V'; return s+k+'T'; } var linker = function(scope, element, attrs) { scope.$watch('ir',function(){ if (!scope.ir) return; element.html(jQuery('#'+getTemplate(scope.ir)).html()).show(); $compile(element.contents())(scope); }) } return { restrict: "E", rep1ace: true, link: linker };});
and patterns:
<div id=HVT style="display:none"> <p>horizontal view template</p> </div> <div id=HET style="display:none"> <p>horizontal {{1+5}} Edit template</p> </div> <div id=VVT style="display:none"> <p>vertical view template</p> </div> <div id=VET style="display:none"> <p>vertical Edit template</p> </div>
I am sure there is a smarter way. is it better to use templateUrl? can someone tell me how to use it in my case?
Edit: There is a problem. the template does not see the area
source share