Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

executing jQuery function after ng-repeat

Thanks in advance for your help. I'm using this tagmanager in my web application. The jQuery function works FINE until this

<input type="text" name="tags" placeholder="Tags" class="tagsManager" />

Is placed under

ng-repeat = "(key,val) in client_proj"

Here is a short snippet of the code

<div class="accordion-group" ng-repeat="(key,val) in client_proj"><!--For Every Project in Project List-->
  <div class="accordion-heading" style="background-color:#EFF8FB">
    <a class="accordion-toggle" data-toggle="collapse" data-parent="#mainAccordion" href="#{{val.id}}" ng-click="disableEditor()">
      <div align="center">{{val.title}}</div>
    </a>
  </div>
  <div id="{{val.id}}" class="accordion-body collapse">
    <div class="accordion-inner" style="font-size:12px; background-color:white">
      <strong>Technologies Exposure:</strong><br/>
      <div ng-hide="editorEnabled">{{val.exposure}}</div>
      <div ng-show="editorEnabled">
        <textarea ng-show="editorEnabled" class="span12" ng-model="val.exposure" rows="12" style="resize:vertical"></textarea>
        <input type="text" name="tags" placeholder="Tags" class="tagsManager" />

It appears as a normal input without doing any of its functions like creating a new tag after pressing, or enter.

Can anyone tell me what's happening?

like image 975
user1166085 Avatar asked Mar 03 '13 08:03

user1166085


1 Answers

1.Create a custom directive that acts as a wrapper for your jQuery plugin:

angular.module('<YOUR APP OR MODULE>').directive('tagsManager', function () {
    return {
        restrict: 'A',
        link: function (scope, element, attrs) {
            element.tagsManager();
            //whatever other logic would go here
        }
    };
});

Then remove the automatic initialization of tabsManager (something like $('<SELECTOR>').tagsManager(); or jQuery('<SELECTOR>').tagsManager(); ) from your script

Ultimately, in your ng-repeat, add the directive to the input element (optionally add other attributes -- you might have to program the behavior for these attributes within your directive -- if they are required)

<input tags-manager>

This will make AngularJS initialize tabsManager on your inputs (via the custom directive) after they are rendered in the DOM.

Makes sense?

like image 190
holographic-principle Avatar answered Oct 13 '22 00:10

holographic-principle