When do we know the actual width of an element in Angular?

前端 未结 4 1343
梦如初夏
梦如初夏 2021-01-31 17:22

I\'m tring to create a directive that will center a div.

So far, I have this code:

app.directive(\"setcenter\", function () {
    return {
        scope:         


        
4条回答
  •  忘了有多久
    2021-01-31 18:04

    Can't comment yet, therefore this answer. Found a similar solution like the one strom2357 is suggesting. $timeout works really well to let you know when the dom is ready, and it is super simple. I am using this solution to get the ui-view element width. Found it in a fiddle.

    var app = angular.module('app', []);
    
    app.controller('MyController', function($timeout, $scope){
    
      $timeout(function(){
        //This is where you would get width or height of an element
        alert('DOM ready');
      });
    
      alert('DOM not ready');
    
    });
    

提交回复
热议问题