javascript - In Angularjs, how do I review the DOM after a route change? -
in app use ng-view
switch out views. need manipulate elements such change width , position. when try on controller i'm getting, expected, unable property 'setattribute' of undefined or null reference
.
i know happening since js doesn't know dom has changed.
since i'm running heavy plugins work sqlite in windows 8 can't post code.
this template being loaded ng-view
<div id="productslist" class="container"> <div class="product" ng-repeat="product in products"> <div class="details"> <img src="img/detail-list-back.png" class="texture" /> <div class="heading"> <p class="title">{{product.name}}</p> <img src="img/products/title-shadow.png" class="title-shadow"/> </div> <div class="text"> <div class="text-container"> <p class="intro" ng-hide="product.intro == null">{{product.intro}}</p> <p class="title">curves</p> {{product.prodtext}} </div> </div> </div> <div class="image" style="background-image:url('img/products/nanoslim-bkg.jpg')"></div> </div> </div>
some of angular. loop breaking since doesn't know sections exist:
var totalprod = res.rows.length; var windoww = window.innerwidth; var sections = document.queryselectorall('#productslist .product'); var textarea = document.queryselectorall('#productslist .text'); document.getelementbyid('productslist').setattribute('style', 'width:' + (windoww * totalprod) + 'px'); (var = 0; < sections.length; i++) { sections[i].setattribute('style', 'width:' + windoww + 'px'); }
everything else works fine. i'm trying bypass using ng-style having issues there.
in angular, dom manipulations should done in directives possible. here's example of setting width window width:
.directive('fullwidth', function() { function link(scope, element, attrs) { var windoww = window.innerwidth; element.css({width: windoww + 'px'}); } return { link: link }; });
now in view
<div class="product" full-width ng-repeat="product in products">
Comments
Post a Comment