javascript - How to rebuild ng-repeat when track by value is changed? -


i've got following ng-repeat expression:

ng-repeat="album in albums track (album.id + gallery.layout)" 

as can see track depends on album's id , gallery layout. when change gallery layout nothing happens - looks ng-repeat doesn't expect track by value change. fix have add/remove album (since layout changed items updated).

how force angular update ng-repeat? can select last album, remove , add $timeout don't solution.

if objects different based on gallery, 1 option have separate property it. js might like:

$scope.$watch('gallery.layout', injectgallerylayoutids);  function injectgallerylayoutids(gallerylayout){   $scope.albums.foreach(function(album){     album.idforgallery = album.id + gallerylayout;   }); } 

and instead track idforgallery .

if want avoid modifying album objects, can use wrappers (of course, use additional memory every album):

$scope.$watch('gallery.layout', updategalleryalbums);  function updategalleryalbums(gallerylayout){   $scope.galleryalbums = $scope.albums.map(function(album){     return { album: album, id: album.id + gallerylayout };   }); } 

however, impression problem you're trying solve might better solved either:

1) pure css. add different class parent element layout name, , draw items in detail necessary. show/hide items, , restyle via css.

if structure of layouts different pure css approach feasible, option might be:

2) have directives or views different gallery layouts, ng-switch between them (or inject layout), , have ng-repeat inside html, , track album.id


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -