自定义指令中的自动增量值

ba1*_*1ar 10 javascript angularjs angularjs-directive

我的自定义指令模板中的自动增量编号各有一个问题.我需要的功能是在按钮单击上添加动态HTML内容.

main.html中
<div class="addTemplateContainer{{dataPoint.id}}"></div> <div ant-add-template-button parent="addTemplateContainer{{dataPoint.id}}"></div>

指令 - ant-add-template-button.js

app.directive('antAddTemplateButton', function ($compile) {
return {
    restrict: 'A',
    link: function (scope, element, attrs) {
        $(element).on('click', function () {
            var compiledeHTML = $compile('<div ant-add-template></div>')(scope);
            $('div.' + attrs.parent).append(compiledeHTML);
        });
    }
}});
Run Code Online (Sandbox Code Playgroud)

指令 - ant-add-template.js

app.directive('antAddTemplate', function () {
return {
    restrict: 'A',
    link: function (scope, element, attrs) {

    },
    templateUrl: '../html/relation-join.html'
}}]);
Run Code Online (Sandbox Code Playgroud)

模板 - my-template.html

<select ng-model="joins[$i]" ng-change="myFunc($i)"></select>
Run Code Online (Sandbox Code Playgroud)

上面的代码适用于添加HTML内容,但我需要使用数组作为用于select的ng-model,并且我需要在每个change事件上调用函数.每次单击按钮时,我都无法找到将$ i作为增量值的方法.
它应该有ng-models作为连接[0],连接[1],连接[2]等等.更具体地说,我不想在这里使用孤立的范围.

任何帮助,将不胜感激.

小智 -1

你可以尝试这个,ng click将首先被触发,然后ng change将被触发