Get Original Array Used in Ng-Repeat When Testing With Protractor

425 views
Skip to first unread message

Peter Jin

unread,
Jul 17, 2014, 4:29:23 PM7/17/14
to ang...@googlegroups.com
I am currently using Protractor to do end-to-end testing on my application.  I've been trying to get the original array that was used to construct a set of ng-repeat elements.  

I tried using the following:

var object = element.all(by.repeater("car in cars"));
console.log(object);

The above returns a small object with only a few properties and methods.

I also tried resolving the above with a $promise:

element.all(by.repeater("car in cars")).then(function(data){
   console.log(data);
});

This logs an object with a long list of properties and methods, but I still do not see anything that would give me the original array used to to create the ng-repeat elements.

How can I access the original array used?

Charly Poly

unread,
Jul 21, 2014, 6:44:33 AM7/21/14
to ang...@googlegroups.com
Hi Peter,

ng-repeat will parse the ng-repeat value with regex and $parse extracted model name to get the value.
If you already know the string passed to ng-repeat, you just have to retrieve the given model value.

Example for 

ng-repeat="car in cars"

You just have to retrieve "cars" model value.

To retrieve the model value, you have 2 options :
  • use by.model() (if your model is attached to a node)
  • user evaluate() (to call on the node where the model scope is attached on)

I hope it will help you.

Regards,
Charly.
Reply all
Reply to author
Forward
0 new messages