-1

I have set the id of the ng-repeat = objectId, ie

<div class="mainListLabel "  ng-if="profile==1" id={{obj.boeId}}
     ng-repeat="obj in mainList" 
     ng-click="getEmployeeInformation(obj.boeId)">{{obj.boedisplayName}}</div>

when I try to do

document.getElementById("1163").value, I get undefined

or when I do

angular.element('#1163').val(), I get ""

I am assuming the reason for this is because the script file is executed before the dynamic id is assigned, is there any way I can get the value from the elemental id

Thejas
  • 379
  • 5
  • 24
  • It is really bad form to do DOM manipulation in Angular - and is likely why you are having difficulty. You should bind the element value to a controller property and use the controller property. Can you describe what you are trying to achieve beyond `.getElementById()`? – Randy Casburn Feb 27 '18 at 18:22
  • 2
    Additionally, `
    ` elements don't have value properties - value properties only exist on HTMLInputElements
    – Randy Casburn Feb 27 '18 at 18:24
  • My requirement is to set the scroll to the record which was last updated in the list – Thejas Feb 27 '18 at 18:27
  • @RandyCasburn Yes the value does not exist for the div, but how can I set the scroll to the partiucular record when we go back to the list page from the detail page? – Thejas Feb 27 '18 at 18:32

1 Answers1

9

<div> elements don't have value properties - value properties only exist on HTMLInputElements


As an (important) side note:

It is really bad form to do DOM manipulation in Angular - and is likely why you are having difficulty. You should bind the element value to a controller property and use the controller property.

lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
Randy Casburn
  • 13,840
  • 1
  • 16
  • 31