admin管理员组文章数量:1377570
I'm doing a $http.get
to get json data, which is then used to populate the views with something like
$scope.getIdeas = function() {
$http.get(ideasUrl)
.success(function(data) {
$scope.ideas = data;
console.log($(".ideas-list").height()); // No height yet =(
})
};
This then populates the view
<ul ng-cloak class="ideas-list" ng-init="getIdeas()">
<li class="idea"
ng-repeat="idea in ideas"
>{{idea.text}}</li>
</ul>
However, on the success
call, the .ideas-list
doesn't have a height yet. Where would I be able to get the populated view height? Is there an event I can hook into?
I'm doing a $http.get
to get json data, which is then used to populate the views with something like
$scope.getIdeas = function() {
$http.get(ideasUrl)
.success(function(data) {
$scope.ideas = data;
console.log($(".ideas-list").height()); // No height yet =(
})
};
This then populates the view
<ul ng-cloak class="ideas-list" ng-init="getIdeas()">
<li class="idea"
ng-repeat="idea in ideas"
>{{idea.text}}</li>
</ul>
However, on the success
call, the .ideas-list
doesn't have a height yet. Where would I be able to get the populated view height? Is there an event I can hook into?
- -1 for mixing jQuery with Angular, making the question and answer more than a little misleading. Best practice for Angular is to not mix jQuery with it as it's antithetical to the Angular model and it's "not the Angular way" - reason being that jQuery works on the DOM directly which conflicts with the fact that in Angular the DOM is generated by a render engine which can conflict (often in bad/bizarre/unpredictable ways). I'd like to see a solution in pure Angular rather than mixed Angular/jQuery. – tpartee Commented Aug 3, 2017 at 3:07
1 Answer
Reset to default 7Use setTimeout
(or preferably the $timeout
service) so that Angular can change the dom before you check the height:
$scope.getIdeas = function() {
$http.get(ideasUrl)
.success(function(data) {
$scope.ideas = data;
$timeout(function(){
console.log($(".ideas-list").height());
});
})
};
本文标签: javascriptHow do I get the height of an element after it is populated by angularjsStack Overflow
版权声明:本文标题:javascript - How do I get the height of an element after it is populated by angularjs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744463894a2607399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论