Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Ng-Click comming from Ng-Include doesn't interpolate $index #13750

@willaleksander

Description

@willaleksander

Angular: 1.4.3
I'm try to inject some dynamic html using ngInclude, ngRepeat and the $index, but I'm having some troubles on ngClick,
something like that:

myApp.controller('myController', ['$scope', '$compile', function($scope, $compile) {
    $scope.start = function(){
        var myController = angular.element(document.getElementById("myController"));
        var dynamicContainers = angular.element(document.getElementById("dynamicContainers"));

        dynamicContainers.html('<ul id="sortableConfig2" style="list-style-type"> <li class="col-md-6 col-sm-6 ui-state-default"  id={{$index}} ng-include="\'./resources/includes/include3.html\'" ng-repeat="item in [0,1,2,3,4,5]" > </li></ul>');

        myController.scope().activateView(dynamicContainers);
    }

    $scope.activateView = function(ele) {
        $compile(ele.contents())($scope);
        $scope.$apply();
    };

    $scope.start();
}]);

And inside the include3.html a have some codes, all using the $index to keep the dynamism.

    <div id="panel{{$index}}hover" class="icons_edit_card">
         <i class="fa fa-cog ng-bind" ng-click="showConfigPanel($index)"></i>
         <i class="fa fa-pencil ng-bind" ng-click='showTypePanel($index)'></i>
    </div>
<div class="overlay">
    <div id="panel{{$index}}overlay" class="container-modal-dashboard">
        <div class="title-modal-dashboard" style="padding-bottom: 4px;" ng-show="paineis[{{$index}}].show">Placar - {{paineis[$index].type}} de Vendas</div>

        ...

All the "$index" are being interpolated, except on ng-click

  1. If use ng-click="showConfigPanel($index)" the html doesn't interpolate and inspecting the element it appears as ng-click="showConfigPanel($index)"
  2. If I use ng-click="showConfigPanel({{$index}})" it shows "Error: [$parse:syntax] Syntax Error: Token '{' invalid key ..."
  3. And if a use ng-click="showConfigPanel('{{$index}}')" the html is rendered as ng-click="showConfigPanel('0')" but if I click on it link the value passed to the function is '{{$index}}' not 0

I tried the solution in this issue #4627, something like that ng-click="showConfigPanel(''+$index)" or ng-click="showConfigPanel('test'+$index)" but it stills writing literally the "$index"

Exist any workarround on it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions