Getting $parent.$index inside a custom directive

前端 未结 1 1804
天命终不由人
天命终不由人 2020-12-22 05:27
  • {

    1条回答
    •  盖世英雄少女心
      2020-12-22 06:12

      This sample can helps you to figure out how can get index or etc ... in directives.

      var app = angular.module("app", []);
      
              app.controller("controller", function ($scope) {
      
                  $scope.array1 = [
                      {id: "1-1"},
                      {id: "1-2"}
                  ];
      
                  $scope.array2 = [
                      {id: "2-1"},
                      {id: "2-2"}
                  ];
      
              });
      
              app.directive("exampleDirective", function () {
                  return {
                      restrict: "A",
                      scope: {
                          exampleDirective: "="
                      },
                      link: function (scope, element, attr, ngModel) {
                          console.log(scope.exampleDirective)
                      }
                  }
              })
      
      
      
          
      
      
      
          
      • {{value.id}}
        • {{j.id}}

          array1 index: {{$parent.$index}}

          array2 index: {{$index}}

      0 讨论(0)
    提交回复
  • 热议问题