0

I know I can set html src tag like <img ng-src="{{phone.imageUrl}}">. But how can I set an id tag like <span id="sourceId::{{post.id}}" class="count"></span> ? I tried <span id="{{ 'sourceId::'post.id }}" class="count"></span> but it didn't work.

4
  • Basically you should not change Id of elements. it is there to identify the element and get it and manipulate it. Commented Feb 18, 2015 at 6:52
  • Agree with @JenishRabadiya, but id="sourceId::{{post.id}}" should set id correctly Commented Feb 18, 2015 at 6:53
  • Thou shall not change ID's consider using a data-* attribute for this kind of situations Commented Feb 18, 2015 at 6:57
  • ya agreed that @karaxuna Commented Feb 18, 2015 at 6:57

2 Answers 2

1

It worked for me.

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="[email protected]" src="https://code.angularjs.org/1.3.13/angular.js" data-semver="1.3.13"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <span id="{{name}}" class="count">Jeinsh</span>
  </body>

</html>

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
});

here is working plunk => link

Inspect the element in developer tool on span and you will get updated id there.

Sign up to request clarification or add additional context in comments.

Comments

1

As @karaxuna said, the following should work

id="sourceId::{{post.id}}"

Or doing the string concatenation inside the {{}} with a +

id="{{'sourceId::' + post.id}}"

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.