Using ng-style with backgroundImage url

4,645 views
Skip to first unread message

Nicholas Parker Stanford

unread,
Aug 20, 2012, 6:27:48 PM8/20/12
to ang...@googlegroups.com
Hi -

It seems that if you use ng-style like ng-style="{backgroundImage: img_loc}" you need have img_loc include url(), e.g. img_loc='url(img.jpg)';. I want to know if there is a way to put something in the html that looks more like this:

ng-style={backgroungImage: 'url( img_loc)'} 

?

I included a jsfiddle. The bottom div is what works. I want to know if something that looks like the middle div can work. 


Thanks

Anders Hessellund Jensen

unread,
Aug 21, 2012, 8:04:53 AM8/21/12
to ang...@googlegroups.com

Anthony Bullard

unread,
Aug 21, 2012, 12:18:10 PM8/21/12
to ang...@googlegroups.com
I think for things like this it's more common to return a value from a function that is called.  That way you don't have to muddy up your view, and it's easily maintainable in your controller code.  Something like this: http://jsfiddle.net/CSEQe/18/

Don't know if using 0.9.19 was mission critical to your example, but that is JSLint valid, Angular 1.0.1 code that accomplishes the result you wanted.

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages