2014-06-23 75 views
0

Im从我的角度控制器(使用ajax)填充我的页面,并使用ng-show在某些步骤中显示内容。 问题是我需要在ng-show显示元素后调整背景的高度。我怎么做?角度,做ng显示后的东西

控制器的功能看起来像这样

$scope.showProducts = function() { 

    $http({ method: 'GET', url: 'myUrl' }). 
     success(function(data) { 

      $scope.productVisible = true; 

      $scope.products= data; 

      //here i would like to recalculate the height of the document but it hasn't shown the products yet 
    }); 

}; 

这样的HTML:

  <li ng-repeat="product in products" ng-show="productVisible"> 
       {{product.ProductName}} 
      </li> 

回答

0

使用watch订阅的变化,因为它得到反映:

$scope.$watch('productVisible', function (newVal, oldVal) { 

    if(newVal){ 
     //Change height here 
    } 

    }, true); 
+0

谢谢,但它仍然没有触发ng显示 – WIRN

0

ng-show以优先级0执行,因此您可以创建自定义指令wi否定优先级并将其放置在同一元素上 - 这样它将作为最后一个执行。

+0

好吧,这是怎么做到的?我试图谷歌它,但它似乎是一个巨大的话题(我刚刚开始角) – WIRN

+0

你可以看看http://www.bennadel.com/blog/2592-hooking-into-the-complete-event- ngrepeat-loop-in-angularjs.htm?utm_content = bufferf30e8&utm_medium = social&utm_source = twitter.com&utm_campaign = buffer其中解释了创建具有特定优先级的指令。 –