Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

retrieve angularjs ID

<input type="text" ng-attr-id="{{ 'myid-' + q.ID }}" class="ng-pristine ng-untouched ng-valid" id="myid-1"><br />
<input type="text"   ng-attr-id="{{ 'myid-' + q.ID }}" class="ng-pristine ng-untouched ng-valid" id="myid-2"><br />
<input type="text"  ng-attr-id="{{ 'myid-' + q.ID }}" class="ng-pristine ng-untouched ng-valid" id="myid-3">

Open in new window

In angularjs in the js file how can I get the ID number only.  exp... 1 , 2, 3
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I don't understand the context for the question.  Are you saying that you need a reference to the DOM element, and you want to get the "id" attribute value as "1" instead of "my-1"?
Avatar of Seven price

ASKER

here is a better example.
http://plnkr.co/edit/64uNNbIpIyiPoIqMgfqs?p=preview

ok if you see I added a if statement but in the real world it does work.
if (item.QuestionID ==  item.QuestionIDs )
yes
I see this code, but I don't understand yet how it applies to this question.  If you uncomment the if block, does it work, or do you get an error?

 angular.forEach($scope.myData,function(item){
 
  // if (item.QuestionID ==  item.QuestionIDs )
   //{
      question = $filter('filter')($scope.existingList, {
      QuestionID: item.QuestionID
         });
       if(!item.answer && question.length>0){
        item.answer = question[0].Response;
      // } 
     }
    })

Open in new window

sorry, so frustrated with this. what I am trying to do is filter by comparing 2 values.  Just so it can put the value in the text box. no luck.
If you are talking about this line, what is the problem with $filter expression?

 question = $filter('filter')($scope.existingList, {
      QuestionID: item.QuestionID
         });
the filter is taking is taking the value with the foreach loop and for example if I have 456 it put it on line 4 , 5 and 6
or if I have id 30 it takes the value instead of putting it on line 30 it put it on row 3 and then row 30.
OK, I understand that, so now I am trying to understand your question in relation to the Plunker example.
well i was going to lead to my question and try something by using the ID's to compare to the questionid. but if you know a better way please share.
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
tks