简体   繁体   中英

Angularjs ng-repeat: how to target an element

I have a list of div elements, when the customer selected an element, the detail view appear. After the back, i want to target my list on selected element.

<div id="patient{{patient.PId}}" class="div-patient" ng-repeat="patient in patients">
   <p>{{patient.name}}</p>
</div>

I have tested many code to scroll on a selected patient:

$(window).scrollTop($("#patient"+$rootScope.selectedPatient).offset().top);
// or
$("html, body").animate({ scrollTop:angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ) });
//or
$(window).scrollTop(angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' ));

The css div-patient:

position: absolute;
height: 330px;
margin-bottom: 30px;
top: {{360*fixTopCell($index)}}px;

But

$("#patient"+$rootScope.selectedPatient).offset().top

and

angular.element("#patient"+$rootScope.selectedPatient).prop( 'offsetTop' )

Return 0 all the time.

It works when I use a table tag instead of a div .

I see that the function scrollTop is not available in Android 4.X. Are there others solutions to target the element selected after a back on list?

It works when i use a table tag INSTEAD of a div.

Make sure your id is not already used #patient . Maybe you try to call an id already used!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM