1

I have an HTML page, and inside one of its tags, I have a hard coded text (similar to a json format). I want to get this text and save it in an AngularJS scope variable, that I can parse and use dynamically in an other page.

So I want to know if is it doable with AngularJS? If yes, do you have any indication, which directive I can use?

Thank you.

2
  • Why not put it into your js file directly? e.g. main controller scope or rootScope. Commented Sep 9, 2014 at 14:07
  • Because it's an other app that generate this html page for me, with a lot of information. And I don't have control on it. Commented Sep 9, 2014 at 14:13

3 Answers 3

2

If you try to get the value of your element. Try this:

In your HTML:

<span id="foo">FOOFOOBAR</span>

In your angular controller :

$scope.foo = angular.element( document.querySelector( '#foo' ) );

or in a classic JS :

var foo = document.getElementById('soap-response').innerText;
Sign up to request clarification or add additional context in comments.

Comments

0

If you have id, you can do this angular.element(document.querySelector('#id')).html() and put it on scope

Comments

0

Get your "hard coded text" with Dom Manipulation in your angular controller.

Then transform it to an object with JSON.parse

Comments

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.