javascript - Trying to set a default background picture using Angular.js -


i'm new angular.js , i'm running problem. i'm using ng-repeat iterate through list of news items. each item has title , body, have optional picture url used background.

i can news item elements picture urls display when there url present. see sample code below.

<li class="news-item col-md-6" ng-repeat="announcement in news.announcements | limitto:8" ng-style="{'background-image': 'url({{announcement.url}})'}"> 

i need set announcement.url value default background picture url when announcement.url null or undefined. not sure how can go this.

any appreciated.

thanks!

<li class="news-item col-md-6" ng-repeat="announcement in news.announcements | limitto:8" ng-style="{'background-image': 'url({{announcement.url || \'path default image\'}})'}"> 

anything between {{ , }} angular expression (similar javascript far beginner concerned). can include || operator (a logical or) , put path default image in string after that. if announcement.url null or undefined "falsy" , latter half of or conditional used.

edit: notice escaped string delimiters (\') because nested inside string uses delimiters.


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -