Yuri Drobkov
Yuri Drobkov

Reputation: 183

Get element content in angular (alternative to .html() in jQuery)

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.

Upvotes: 1

Views: 2646

Answers (2)

Murugesan
Murugesan

Reputation: 161

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>

Upvotes: 3

ibrahimbayer
ibrahimbayer

Reputation: 262

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.

Upvotes: 0

Related Questions