javascript - angularjs find properties of div in directive -


new angular, new stackoverflow. been trying solve days. here problem:

i want center group of boxes.

is there way access properties of div's (with id or class names) , manipulate them in directive?

in html creating divs ng-repeat, divs boxes displayed. have directive i, now, trying use find , manipulate properties of div's/directives in html, can't seem this.

i have googled lot , have found similar issues nothing seems work in code.

here's fiddle: http://jsfiddle.net/3m87r/

app.directive('someboxes', function() {     return function(scope, element, attrs)     {         element.css('border', '1px solid white');         //element.css('width', '200px');          var body = angular.element(document).find('.bookitem');         console.log(body[0].offsetwidth);          if(scope.$last)         {             //console.log("element name is: " + element.attr("class"));             //console.log("element is: " + element);             //console.log($(".bookitem").children("div").attr("class"));             //console.log($('.container').children('div').attr('class'));         }     }; }); 

thank provided.

the reason because ng-repeat changes dom, children elements not available during directive compilation. $watch needed on child elements.

this notifies directive child elements added , perform operation on them.

the $watch must skip nodetype "comment:(type 8)"

here working fiddle: http://jsfiddle.net/3m87r/3/

the part in link:

 link: function ($scope, element, attrs, controller) {                     $scope.$watch(element.children(),function(){                     var children = element.children();                     for(var i=0;i<children.length;i++){                         if(children[i].nodetype !== 8){                             angular.element(children[i]).css('background', 'orange');                         }                     }                 });             } 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -