Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未定义Angularjs ng重复传递的索引_Javascript_Angularjs - Fatal编程技术网

Javascript 未定义Angularjs ng重复传递的索引

Javascript 未定义Angularjs ng重复传递的索引,javascript,angularjs,Javascript,Angularjs,我试图在ng repeat中打开和关闭按钮,view on map起作用,但当它更改为remove marker时,它会在控制台日志中向我传递一个错误“ReferenceError:passedIndex未定义”。有办法解决吗 HTML: <li class="displaySubCategory" ng-repeat="communityTheme in community | startFrom:currentPage*pageSize | limitTo:pa

我试图在ng repeat中打开和关闭按钮,view on map起作用,但当它更改为remove marker时,它会在控制台日志中向我传递一个错误“ReferenceError:passedIndex未定义”。有办法解决吗

HTML:

            <li class="displaySubCategory" ng-repeat="communityTheme in community | startFrom:currentPage*pageSize | limitTo:pageSize">
              <div class="categoryImg">
                <img src="img/csvIcon.png" />
                <img src="img/shpIcon.png" />
              </div>
              <div class="categoryDesc">
                <p>{{communityTheme.THEMENAME}}</p>
                <a href="" ng-hide="communityTheme.visibility" ng-click="getMapData(communityTheme.QUERYNAME, $index)">View on Map</a>
                <a href="" ng-show="communityTheme.visibility" ng-click="removeMarker(communityTheme.QUERYNAME, $index)">Remove Marker</a>
              </div>
            </li>
提前谢谢你的帮助


您需要使用track by$index

 <li class="displaySubCategory" ng-repeat="communityTheme in community | startFrom:currentPage*pageSize | limitTo:pageSize track by $index">

你的函数定义是错误的。尝试
$scope.removeMarker=函数(passedIndex){
@HangulSR正如上面的评论中提到的,参数应该是passedIndex,检查编辑的答案你还在吗?知道为什么现在它说不能读取未定义属性的“可见性”吗?我在我的view on map函数中添加了可见性,在我的remove marker函数中它仍然未定义吗?添加一个console.log($scope.community)[passedIndex])并查看它是否具有visibilityYa,它未定义。为什么会这样?是因为异步还是其他原因?@Sajeetharan这意味着$scope.community不包含值,是的,您需要使用if($scope.community)检查
        $scope.removeMarker = function ($index) {

            if($scope.community[passedIndex].visibility)
             {
               $scope.community[passedIndex].visibility =false;
               cities.clearLayers();
             }
            else {
              $scope.community[passedIndex].visibility = true;
            }
        }
 <li class="displaySubCategory" ng-repeat="communityTheme in community | startFrom:currentPage*pageSize | limitTo:pageSize track by $index">
$scope.removeMarker = function (passedIndex) {