AngularJS ng-click功能

时间:2016-02-24 03:57:58

标签: angularjs angularjs-ng-click

请帮助我,我想使用ng-click访问一个函数,如下所示:

             <tr ng-repeat="data in listtalentapegawai">
                <td>            
                    {{data.nip}}
                </td>
                <td>
                    {{data.nama}}
                </td>
                <td>
                    {{data.tgl_grade_terakhir}}
                </td>
                <td>
                    {{data.sem1_2012}}
                </td>
                <td>
                    {{data.sem2_2012}}
                </td>
                <td>
                    {{data.sem1_2013}}
                </td>
                <td>
                    {{data.sem2_2013}}
                </td>
                <td>
                    {{data.sem1_2014}}
                </td>
                <td>
                    {{data.sem2_2014}}
                </td>
                <td>
                    {{data.sem1_2015}}
                </td>
                <td>
                    <button ui-sref=".modal"  ng-click="showAlert(data.nip)">Simulasi</button>
                </td>
            </tr>

data.nip来自ng-repeat="data in listtalentapegawai"

这是我写的状态:

 .state('masterpegawai.alltalenta.modal', {
            url: '/modal',
            views:{
                "modal": {
                    templateUrl : 'public/js/modal.html',
                    controller: 'simulate'
                }
            }
         })

angular.module('routerApp').controller('simulate', ['$scope', function ($scope) {
   $scope.showAlert = function (provider) {
       //console.log('clicked signin ' + provider); 
       $scope.nip = provider;
   }

   $scope.showAlert();
}])

问题是提供商没有价值。实际上我想将show.Aip(data.nip)中的data.nip传递给模态对话框

1 个答案:

答案 0 :(得分:0)

在你的州尝试这个:

.state('masterpegawai.alltalenta.modal', {
    url: '/modal',
    templateUrl : '/your/path/to/html/file.html',
    controller : 'MyPageController'
 })

分别创建控制器:

angular.module('appModule', []).controller('MyPageController', ['$scope', function ($scope) {
   $scope.showAlert = function (provider) {
       alert('clicked signin ' + provider); 
   }

   $scope.showAlert();
}])