1

I'm creating dynamically an element that I need to have control over its width and position. I'm trying to change its style using an input with ng-model and ng-style directive in the created element, in the following manner:
JS:

function createElementAndAppend(){
    element = angular.element("<"+element+" id='inputTag' ng-click='selectClickedElm($event.currentTarget)' ng-style='{width: w + 'px'} placeholder='input'>");
    angular.element(document.getElementById('board')).append($compile(element)($scope));
}

HTML:

<input type="number" ng-model="w" placeholder="change width">

I'm getting an error:

Error: [$parse:ueoe] Unexpected end of expression: {width: w

Obviously the problem is with ng-style='{width: w + 'px'}. How do I write the plus sign to angular will know to interpret the value of w with px as thw final width of the element?

0

1 Answer 1

2

I have not tested it, but this should work:

element = angular.element("<"+element+" id='inputTag' ng-click='selectClickedElm($event.currentTarget)' ng-style='{width: w + \"px\"}' placeholder='input'>");
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.