user1166085 user1166085 - 1 year ago 96
AngularJS Question

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="#{{}}" ng-click="disableEditor()">
<div align="center">{{val.title}}</div>
<div 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?

Answer Source

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) {
            //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?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download