Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
willaleksander opened this issue Jan 12, 2016 · 1 comment
Closed

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

willaleksander opened this issue Jan 12, 2016 · 1 comment

Comments

@willaleksander
Copy link

@willaleksander willaleksander commented Jan 12, 2016

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?

@Narretz
Copy link
Contributor

@Narretz Narretz commented Jan 12, 2016

Please ask support questions on one the support channels: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#question Thanks!

@Narretz Narretz closed this Jan 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.