Search code examples
angularjsbindonce

bindonce with ng-repeat causes errors


I'm trying to use bindonce with an ng-repeat and it is causing the error:

Controller 'bindonce', required by directive 'ngRepeat', can't be found!

Here is the div causing the issue:

<div bo-if="transcripts.userIsAuthorizedForCourseTranscripts" bindonce ng-repeat="module in transcripts.modules">
...
</div>

Solution

  • when you have an ng-repeat it actually creates the element from the clone. This means that for everything in the repeat, the new element has both the bo-if and the bindonce. It seems like you want to only do the repeat if you have authority.

    So if you want to only do the repeat if transcripts.userIsAuthorizedForCourseTranscripts === true then you would nest it like this:

    // This assumes bindonce is declared above
    <div bo-if="transcripts.userIsAuthorizedForCourseTranscripts">
        <div bindonce ng-repeat="i in stuff">
            #This area has bindonce using i
        </div>
    </div>
    

    I also made a fiddle showing this case http://jsfiddle.net/49c5C/1/

    Hope this helped!