1

I've got this element:

<span id="tag_span"> {{ selectedSection }} </span> 

And I want to get its content from controller, which is {{ selectedSection }}. I can get the element like this:

angular.element('#tag_span'); 

but don't know how to get what inside of it. Any ideas?

P.S. document.getElementById won't work in the case so there's no need to suggest it.

EDIT: No jQuery allowed.

3
  • It might be bad idea to pass HTML from controller. Are you sure you want it? What are you trying to do? Commented Aug 22, 2015 at 7:09
  • 2
    Check this link : stackoverflow.com/questions/17230242/… Commented Aug 22, 2015 at 7:15
  • I hope you are not creating duplicate id's because that is the only reason I know of why getElementById will not work. Duplicating ID's will make it impossible to validate your page and cause the page to run in quirks mode on all browsers. The value of the ID attribute, if assigned, must be unique for every element that has an ID on the page. Just a warning. Commented Aug 22, 2015 at 7:54

2 Answers 2

3

You get the value by $scope.selectedSection from your controller.

If you need the get html inside the span element use

angular.element($('#tag_span')).html(); 

You need to reference the jquery before angular js like below.

<script type="text/javascript" src="../../Scripts/jquery-2.1.0.min.js"></script> <script type="text/javascript" src="../../Scripts/angular/angular.js"></script> 
Sign up to request clarification or add additional context in comments.

Comments

0

Your all html elements are properties of $scope, so you could easily access the content via $scope.selectedSection . Your controller function definition must have a scope injection like function controller($scope), that is all.

1 Comment

Not exactly my case, but it helped me to solve the problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.