1

I want to create a new element in my controller and then add a scope variable to this. The way I did it, I only see '{{text}}' in the view instead of the variable value of $scope.text.

That's my code so far:

JS:

var elem = document.getElementById('match-text');
var newElem = document.createElement('span');
newElem.setAttribute('id', 'inner-match-text');
newElem.setAttribute('class', 'ng-binding');
newElem.innerText = '{{text}}';
elem.appendChild(new_elem);

Html:

<h3 id="match-text"></h3>

Maybe this is the totally wrong approach, I don't know. Can someone tell me how to do this properly?

1 Answer 1

1

Is it necessary to use quotes?

newElem.innerText = $scope.text;
Sign up to request clarification or add additional context in comments.

4 Comments

Now I just see this '${$scope.text}', so does not work either
are you using backticks or regular single quotes? you need to use backticks: `
when I use backticks, I get the error message 'string templates are not supported by current js version'
So I guess you're using something lower than ES6? What about not using any quotes at all? I've changed my answer.

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.