How to access image properties after angular ng-repeat?

前端 未结 1 1306
情深已故
情深已故 2021-02-10 10:40

I am trying to get image width and height of an image that I pull from server in order to apply proper style for it. So I am using ng-repeat to fill template :

&         


        
1条回答
  •  长发绾君心
    2021-02-10 11:21

    I don't know what you're trying to do, but it sounds like a job for a directive.

    app.directive('styleParent', function(){ 
       return {
         restrict: 'A',
         link: function(scope, elem, attr) {
             elem.on('load', function() {
                var w = $(this).width(),
                    h = $(this).height();
    
                var div = elem.parent();
    
                //check width and height and apply styling to parent here.
             });
         }
       };
    });
    

    and you'd use it like so:

    
    

    EDIT: If you're not using jquery, this will vary a little.

    0 讨论(0)
提交回复
热议问题