html - Error: $rootScope:infdig Infinite $digest Loop while using $http.get() -


i have list of buttons on html page, when clicked should open url in new page. however, of urls return http 500 error. so, want disable buttons if link behind them returns https 500 error. here html , angular js codes. actually, in html code, there loop going through resources (shown r) related specific data (using data-ng-repeat), , checking maintype of resource, if linkdownload or link, button should appear if link (r.url) not release error.

to check if url releases error or not used isvalid(r.url) function. however, infinite number of error:error: $rootscope:infdig infinite $digest loop.

i made many changes way use isvalid(link) function. unsuccessful. please? how should task while have ng-repeat loop?

part of html page:

<div class="gn-related-resources"      data-ng-if="relationfound">   <h2>{{::title}}</h2>    <div class=""        data-ng-repeat="(type, items) in relations track $index"        data-ng-if="type && type !== 'thumbnails'">     <div class="row list-group-item gn-related-item"          data-ng-repeat="r in items track $index"          data-ng-init="maintype = config.gettype(r, type);">        <div class="col-xs-4" data-ng-if="maintype === 'linkdownload' || maintype === 'link'" >         {{isvalid(r.url)}}         <button type="button"                 class="btn btn-default btn-sm btn-block"                 data-ng-show="isvalid(r.url)"                 data-ng-click="config.doaction(maintype, r, md)">          <span class="visible-lg-*">           {{::(config.getlabel(maintype, type)) | translate}}         </span>         </button>       </div>     </div>   </div> </div> 

part of angularjs directive:

  module   .directive(       'gnrelated',       ['gnrelatedservice',     'gnglobalsettings',     'gnrelatedresources',     function( gnrelatedservice, gnglobalsettings, gnrelatedresources) {       return {         restrict: 'a',         templateurl: function(elem, attrs) {           return attrs.template ||                   '../../catalog/components/metadataactions/partials/related.html';         },         scope: {           md: '=gnrelated',           template: '@',           types: '@',           title: '@',           list: '@',           user: '=',           hasresults: '=?'         },          link: function(scope, element, attrs, controller) {            var promise;           scope.updaterelations = function() {             scope.relations = [];             if (scope.uuid) {               scope.relationfound = false;               (promise = gnrelatedservice.get(                  scope.uuid, scope.types)               ).then(function(data) {                    scope.relations = data;                    angular.foreach(data, function(value) {                      if (value) {                        scope.relationfound = true;                        scope.hasresults = true;                      }                    });                  });             }           }; 

i recommend never such things: {{isvalid(r.url)}}

scope.isvalid = function(link)               {                 $http.get(link).then(                 function(success) {                    return true;                 }, function(error) {                    return false;                 });               }; 

every digest cycle call async call


you have relations list, create promise all, a.e. $q.all([]) , render results respectively.

instead isvalid(r.url) write like:

{{r.requestsucceeded}} 

where requestsucceeded created after run requests


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -