如何在ng-repeat中使用ng-click显示离子弹出窗口

时间:2017-01-22 02:37:43

标签: javascript angularjs ionicpopup

这是我的HTML代码。

    <div class='list' ng-repeat='worker in categories' >
    <br><a class="item item-thumbnail-left" ng-click="showConfirm(worker.$id)">
    <img src="img/tech_support.png">
    <p>{{worker.$id}}</p>
    <p>Address: {{worker.Address}}</p>
    <p><u>more..</u></p>
    </a>
    </div>

这是我的controller.js

man.controller('categoryCtrl',function($scope,$firebaseArray,
                    $firebaseObject,$state,$stateParams,$ionicPopup,$window,$timeout){


        var category = $stateParams.categoryId;
        var categoryRef = Refroot.child('Workers').child(category);

        $scope.categories=$firebaseArray(categoryRef);



        $scope.showConfirm= function(id){

                var workerId = id;

                var workRef = Refroot.child('Workers');

                var lastRef = workRef.child(category).child(workerId);

                $scope.workerlist = $firebaseArray(lastRef);

                var confirmPopup = $ionicPopup.confirm({
                    title: 'Worker Profile',
        });

        confirmPopup.then(function(res) {
                if(res) {
                console.log('Sure!');
                } else {
                console.log('Not sure!');
                }
        });

        console.log(workerId + '' + category + '' + lastRef);
        }


});

希望你们能帮助我,这对我的论文有很大的帮助:)。

1 个答案:

答案 0 :(得分:0)

您应该使用 $ index ,如下所示

    <div class='list' ng-repeat='worker in categories track by $index'  >
            <br><a class="item item-thumbnail-left" ng-click="showConfirm($index)">
            <img src="img/tech_support.png">
            <p>{{$index}}</p>
            <p>Address: {{worker.Address}}</p>
            <p><u>more..</u></p>
            </a>
    </div>