please help me, I would like to access a function using ng-click like this :

             <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 come from ng-repeat="data in listtalentapegawai"

and this is the state I wrote :

 .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();
}])

The problem is provider doesn't have value. Actually I woul like to pass the data.nip from showAlert(data.nip) to a modal dialog

share
    
can you provide a link in jsfiddle.net ? – Anik Islam Abhi Feb 24 '16 at 4:05
    
Since you are using ui-sref, do you want to change state and show alert dialog? – MrNobody Feb 24 '16 at 4:06
    
I am new to angular, actually i would like to open modal and put data.nip value inside modal, but first I would like to learn how to call a function from ng-click. I have tried to delete the ui-sref, but the result still nothing appear – Arief Grando Feb 24 '16 at 4:09
    
what is data.nip and where is it defined? – Satej S Feb 24 '16 at 4:18
    
data.nip come from ng-repeat="data in listtalentapegawai" – Arief Grando Feb 24 '16 at 7:22

try this in your states:

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

And create controller separately:

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

   $scope.showAlert();
}])
share
    
the modal pop up but the alert doesn't – Arief Grando Feb 24 '16 at 7:20
    
@AriefGrando It should popup if you call the function. Updated code in my answer, try it now. – xSaber Feb 24 '16 at 8:00
    
Hi xSaber, provider undefined – Arief Grando Feb 24 '16 at 8:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.