Angularjs launches directive after area loaded with $ http data

I need to run a directive that launches the jQuery jPager plugin after the HTTP call has loaded the elements

in the DOM.

jquery works fine, but I can’t get the directive to start after the screen is displayed (it starts before and therefore the area is empty)

I tried using demodulation of $ emit and $ broadcast, but still can not start it.

Area loads tags

in itemContainer, then jQuery prints the data.
<div wss-pager class="holder"></div>
        <ul id="itemContainer" ng-bind-html="ctData"></ul>

////

function loadData() {
                $http({
                        method: 'GET',
                        url: 'api/getMyData',

                    }).
                    success(function(data, status, headers, config) {
                        // deferred.resolve(data);
                        $scope.ctData = data.m_StringValue;
                    //    
                        $scope.$emit('UpdateJPages');
                    }).
                    error(function(data, status, headers, config) {
                        alert("error" + data);
                        $scope.ctData= "";
                    });

            };

/////////

  angular.module('app').directive("wssPager", [function () {
            return {
                restrict: "A",
                link: function (scope, elem, attrs) {
                    scope.$on('UpdateJPages', function() {

                        $("div.holder").jPages({
                            containerID: "itemContainer",
                            perPage: 5,
                            startPage: 1,
                            startRange: 1,
                            midRange: 5,
                            endRange: 1
                        });


 });
+4
source share
2 answers

Use ng-if if cData is empty before this call is used as follows:

<div wss-pager class="holder" ng-if="ctData"></div>

, var, . loaded

<div wss-pager class="holder" ng-if="loaded"></div>
function loadData() {
    $scope.loaded = false;
    $http({
        method: 'GET',
        url: 'api/getMyData'
    })
    .success(function(data, status, headers, config) {
        // deferred.resolve(data);
        $scope.ctData = data.m_StringValue;
        $scope.loaded = true
        $scope.$emit('UpdateJPages');
    })
    .error(function(data, status, headers, config) {
        alert('error' + data);
        $scope.ctData= '';
    });
};
+5

, , . , , .

$timeout, .

 $timeout(function () {
       $scope.$emit('UpdateJPages');
         });
+1

All Articles