{"id":2173,"date":"2022-08-30T15:22:39","date_gmt":"2022-08-30T15:22:39","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/04\/angular-not-compiling-inside-custom-directive-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:22:39","modified_gmt":"2022-08-30T15:22:39","slug":"angular-not-compiling-inside-custom-directive-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/angular-not-compiling-inside-custom-directive-collection-of-common-programming-errors\/","title":{"rendered":"Angular not compiling inside custom directive-Collection of common programming errors"},"content":{"rendered":"<p>I have a directive that looks like this:<\/p>\n<pre><code>app.directive('fieldsetCollapse', function() {\nreturn {\n    restrict: 'A',\n    scope: {},\n    compile: function(tElement, tAttrs, transclude) {\n        var wrapperElement = angular.element(''),\n            legendElement = tElement.find('legend'),\n            collapsibleContent = tElement.children().not('legend'),\n            toggleBtn = angular.element('');\n\n        legendElement.css('cursor', 'pointer')\n                      .attr('ng-click', 'toggle()');\n\n        tElement.css({\n            'position': 'relative',\n            'marginLeft': '20px'\n        });\n        tElement.prepend(toggleBtn);\n\n        angular.forEach(collapsibleContent, function(obj, i) {\n            $(obj).remove();\n            wrapperElement.append(obj);\n        });\n\n        tElement.append(wrapperElement);\n\n        return function(scope, element, attrs) {\n            var directiveValue = (scope.$eval(attrs.gaigCollapsibleFieldset));\n            scope.isOpen = (directiveValue == undefined) ? true : directiveValue;\n\n            scope.toggle = function() {\n                scope.isOpen = !scope.isOpen;\n            }\n\n        }\n    }\n}\n<\/code><\/pre>\n<p>});<\/p>\n<p>Which works with this markup:<\/p>\n<pre><code> ... \n<\/code><\/pre>\n<p>If I try adding anything inside such as this:<\/p>\n<pre><code>{{foo}}\n<\/code><\/pre>\n<p>&#8230;where foo is defined on the scope of my controller, the output is<\/p>\n<pre><code>{{foo}}\n<\/code><\/pre>\n<p>Angular isn&#8217;t compiling anything I add between my tag with the directive. Am I missing something to make this happen inside my directive?<\/p>\n<ol>\n<li>\n<p>You are creating an isolated scope in the directive definition object<\/p>\n<pre><code>return {\n    restrict: 'A',\n    scope: {} \/\/<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-01-04 02:51:15. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a directive that looks like this: app.directive(&#8216;fieldsetCollapse&#8217;, function() { return { restrict: &#8216;A&#8217;, scope: {}, compile: function(tElement, tAttrs, transclude) { var wrapperElement = angular.element(&#8221;), legendElement = tElement.find(&#8216;legend&#8217;), collapsibleContent = tElement.children().not(&#8216;legend&#8217;), toggleBtn = angular.element(&#8221;); legendElement.css(&#8216;cursor&#8217;, &#8216;pointer&#8217;) .attr(&#8216;ng-click&#8217;, &#8216;toggle()&#8217;); tElement.css({ &#8216;position&#8217;: &#8216;relative&#8217;, &#8216;marginLeft&#8217;: &#8217;20px&#8217; }); tElement.prepend(toggleBtn); angular.forEach(collapsibleContent, function(obj, i) { $(obj).remove(); wrapperElement.append(obj); }); tElement.append(wrapperElement); return [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2173","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2173"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2173\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}