The document is ready in AngularJS

I want to run some jQuery code when you click on the checkbox. The problem is that when I click on selectbox the first time the page loads, nothing happens. But when I click again, jQuery code is executed. I tried setting angular.element (ready) as shown below, but it does not work:

angular.element(document).ready(function() {
        $http.get($rootScope.appUrl + '/nao/test/test')
            .success(function(data, status, headers, config) {
                $scope.test = data.data;
        });
        $scope.testa = function() {
                $('.checkboxfisk').click(function() {
                var fish = $(this).attr('id');
                alert(fish);    
                });

        };
});

<tr ng-repeat="info in test"><td>{{info.stracka}}</td><td>{{info.tid}}</td><td><input type="checkbox" id="{{info.id}}" class="checkboxfisk" ng-click="testa()"></tr>
+4
source share
4 answers

DOM Angular . jQuery postLink ( Angular ). , .

Angular :

AnuglarJS: :

, . jQuery click. jQuery Angular click :

$scope.testa = function(id) {
    alert(id);
};

ng-click, :

<input type="checkbox" 
       id="{{info.id}}" 
       class="checkboxfisk" 
       ng-click="testa(info.id)">
+2

Angular "On DOM Ready", .

Angular DOM, , , AJAX ($http.get), .

- :

<body ng-controller="MainCtrl">
  <input type="checkbox" chk-Sample="" >

<script>

var myApp = angular.module('myApp', []);

myApp.controller('MainCtrl', ['$scope', function ($scope) {}]);

myApp.directive("chkSample", function() {
    return {
            restrict: "A", //A - means attribute
            link: function(scope, element, attrs, ngModelCtrl) {
               $(element).click(function() {
                 var fish = $(this).attr('id');
                 alert(fish);    
               });
            }
        };
});

...

myApp.directive("chkSample",... chk-Sample="", , angulare , .

0

, , , ng-click jQuery click(), , . , . , , . , , .

0

, , : -

    $timeout(function(){
     if(condition){
       /*
             code you want to execute */
        }

    });  
0

All Articles