Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I would like to know how to put an angularjs model as the value for an html attribute. such as:

<div ng-controller="deviceWidth" width={{width}}> </div>

also, how would I do this within <style> markup? Where would I put ng-controller?

div {
    width:{{width}}
}

Thanks, Ben

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You'd better do create own custom directive instead of the "static" width, and interpret the interpolation with $observe function.

Post pretty similar, involving some solutions:
String Interpolation Won't Work when Setting Attribute Values on a Custom Directive

Concerning the markup, you'd better play with ng-class, whose value comes from your controller logic.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.