在ng-bind-html之后没有在ng-init中获得正确的高度

时间:2016-12-17 07:49:28

标签: javascript angularjs

       $scope.checkbioheight = function () { 
  var h = $('.c').outerHeight();
        console.log(h);
        if (h > 60) {
           //do something
        } else  {
            //do something
        }
}
<p ng-cloak ng-bind-html="renderHtml(ViewAboutCoach)" class="c" data-ng-init="checkbioheight()" ></p>

我从console.log得到5px的高度, 数据加载后其实际为229px。为什么它返回错误。如果我必须使用settimeout,那么角度JS的好处是什么,我可以使用jquery。

1 个答案:

答案 0 :(得分:0)

从角度1.5.x开始,您可以在应用程序中使用生命周期钩子。 如果你制作一个组件,那么你可以使用$ postLink()

有关https://docs.angularjs.org/api/ng/service/ $ compile

的更多信息

另一方面,您可以尝试使用此

 $timeout(function(){
    var h = $('.c').outerHeight();
    console.log(h);
    if (h > 60) {
       //do something
    } else  {
        //do something
    }});