在ng-repeat之后执行jQuery函数

时间:2021-03-22 20:36:53

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

在此先感谢您的帮助。我在我的网络应用程序中使用这个tagmanager。 jQuery函数在此之前一直运行FINE

<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?

谁能告诉我发生了什么?

1 个解决方案

#1


10  

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

1.创建一个自定义指令,作为jQuery插件的包装器:

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

然后从脚本中删除tabsManager的自动初始化(类似$(' ')。tagsManager();或jQuery(' ')。tagsManager();)

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)

最后,在ng-repeat中,将指令添加到input元素(可选地添加其他属性 - 您可能必须在指令中编写这些属性的行为 - 如果需要的话)

<input tags-manager>

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

这将使AngularJS在DOM中呈现后,在输入上(通过自定义指令)初始化tabsManager。

Makes sense?

说得通?

#1


10  

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

1.创建一个自定义指令,作为jQuery插件的包装器:

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

然后从脚本中删除tabsManager的自动初始化(类似$(' ')。tagsManager();或jQuery(' ')。tagsManager();)

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)

最后,在ng-repeat中,将指令添加到input元素(可选地添加其他属性 - 您可能必须在指令中编写这些属性的行为 - 如果需要的话)

<input tags-manager>

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

这将使AngularJS在DOM中呈现后,在输入上(通过自定义指令)初始化tabsManager。

Makes sense?

说得通?