如何将userId从浏览器传递给量angular器?

所以我已经在我的angular2组件中使用* ngFor来呈现用户。

<ul> <li *ng-for="let user of users"> <input [(ng-model)]="user.name"> <button (click)="remove(user._id)">Remove</button> <a [routerLink]="['/edit',user._id]"> <i class="fa fa-eye fa-fw"></i> </a> </li> </ul> 

现在在我的量angular器testing中,当我点击这个链接时,不导航到编辑组件。

所以我想要做的是:

通过传递任何user._id导航到editComponent,但我不知道如何将user._id从模板传递给量angular器e2etesting。

以下是我的testing:

 it('should redirect to edit', () => { browser.get('/edit/'+user._id); //here I want to pass user._id which is inside *ngFor of browser browser.waitForAngular(); }); 

任何方式来做到这一点? 谢谢

使用evaluate()方法提取值表单作用域variables。查看下面的例子。

 it('should redirect to edit', () => { element(by.buttonText("Remove")).evaluate("user._id").then(function(userId){ browser.get('/edit/'+userId); browser.waitForAngular(); }) });