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.

Yuri Drobkov
  • 183
  • 2
  • 12
  • It might be bad idea to pass HTML from controller. Are you sure you want it? What are you trying to do? – dfsq Aug 22 '15 at 07:09
  • 2
    Check this link : http://stackoverflow.com/questions/17230242/angular-element-vs-document-getelementbyid-or-jquery-selector-with-spin-busy-c – bob Aug 22 '15 at 07: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. – Blindman67 Aug 22 '15 at 07:54

2 Answers2

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>
Murugesan
  • 161
  • 3
  • 7
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.

ibrahimbayer
  • 262
  • 1
  • 9