css - view does not change background image -


i have template in call function , have directive element,

.container-wrapper{"ng-controller" => "movierowctrl"}   %i.fa.fa-info-circle{"ng-click" => "updateselectedmovie(movie)"}  #big-box-container{"ng-if" => "rowactive"}   %movie-details{:movie => "selectedmovie"} 

the function inside directive,

app.directive('moviedetails', moviedetailsdirectivefn)   .controller('movierowctrl', ['$scope', '$rootscope', movierowctrlfn]);  function moviedetailsdirectivefn($animate) {   return {     restrict: 'e',     scope: {       movie: '=',     },     templateurl: '../assets/angular-app/templates/_movie-info.html'   } }  function movierowctrlfn($scope, $rootscope) {   $scope.updateselectedmovie = function updatevisiblemovieindexfn(movie) {     $scope.selectedmovie = movie;     $rootscope.$broadcast('movierowactivated', {targetscopeid: $scope.$id});     $scope.rowactive = true;   } } 

as can see set movierowctrl controller .container-wrapper.

so when updateselectedmovie(movie) function fires sets $scope.rowactive true (showing element) , inject _movie-info.html template inside %movie-details element.

this works fine.

in _movie-info.html template have this,

.movie-background{"ng-style" => "{'background-image':'url(https://image.tmdb.org/t/p/w1280{{movie.backdrop}})'}"} 

which results in,

<div class="movie-background" ng-style="{'background-image':'url(https://image.tmdb.org/t/p/w1280/lxoqbocx1t5a3yhjeifjzokigwh.jpg)'}"  style="background-image: url(&quot;https://image.tmdb.org/t/p/w1280/nbirdhotupdd9hkdbry02a8vhpv.jpg&quot;);"> 

so creates ng-style, , normale style attribute element.

the problem when fire updateselectedmovie(movie) ng-style attribute gets updated new url, style attribut not changed.

<div class="movie-background" ng-style="{'background-image':'url(https://image.tmdb.org/t/p/w1280/15pbztjrj4zgqa8xs0otl70piqi.jpg)'}"  style="background-image: url(&quot;https://image.tmdb.org/t/p/w1280/nbirdhotupdd9hkdbry02a8vhpv.jpg&quot;);"> 

any ideas why ng-style gets updated, other style not?

there not need use {{}} inside ng-style, use + string concatenation while concatenating scope variable inside ng-style expression.

.movie-background{"ng-style" =>        "{'background-image':'url(https://image.tmdb.org/t/p/w1280' + movie.backdrop +')'}"} 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -