Note that there are some explanatory texts on larger screens.

plurals
  1. POTroubles using ng-if inside html template of a directive
    primarykey
    data
    text
    <p>I have recently start working with Angular.JS, and i have arrived to a scenario that i don't know how to correctly handle it.</p> <p>Let me explain what i have and what i'm trying to do (i suppose it's the correct way of handle that scenario):</p> <ul> <li><p>The directive (panelMenu) that loads a template through templateUrl and define it's own controller with one property (visibilidad). (That property value is supposed to be gathered as the result of a service that i have working, but for the easiness of the example i will remove that part)</p> <pre><code>.directive('panelMenu', function () { return { restrict: 'E', templateUrl: './partials/panelMenu.html', replace: true, transclude: false, controller: ['$scope', function ($scope) { $scope.visibilidad = false; } ], link: function (scope, element, attrs) { } }; }) </code></pre></li> <li><p>The template (panelMenu.html) that is being loaded by the directive, that uses ng-if attached to the visibility property defined inside the directive controller to dinamycally add/remove the html.</p></li> </ul> <p>panelMenu.html:</p> <pre><code>&lt;div class="panel-menu" ng-if="visibilidad"&gt; &lt;a class="brand" href="#"&gt;Menú [Tablet] - Valor {{visibilidad}}&lt;/a&gt; &lt;/div&gt; </code></pre> <p>And that's what i got from the browser console:</p> <p>Error: [$compile:ctreq] Controller 'panelMenu', required by directive 'ngIf', can't be found!</p> <p>I have been reading a lot about how does works ng-if and scopes...but it's supposed that ng-if should inherit from the parent scope (controller defined on the directive). Do iam right?.</p> <p>BTW, i'm using the custom directive on index.html like that:</p> <pre><code>&lt;panel-menu&gt;&lt;/panel-menu&gt; </code></pre> <p>Besides the main problem, i would want to know if i'm doing it correctly, or if the ng-if condition should be placed on the directive tag (accessing the service that i had mentioned before to get the value) instead on the html template.</p> <p>Thanks in advance for all.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload