我正在尝试使用量角器为元素构建一个选择器,但事实证明这个元素与另一个元素具有相同的模型。当我检查每个元素时,我得到以下html:
元素1:
<select class="form-control ng-pristine ng-valid ng-touched" data-ng-model="account.accountType" data-ng-options="opt.code as opt.description for opt in bankPersonCtrl.catalogs.bank.bankAccountTypes"><option value="" disabled="" selected="" class="">Seleccione</option><option value="0" selected="selected" label="Ahorros">Ahorros</option><option value="1" label="Corriente">Corriente</option></select>
元素2:
<select class="form-control ng-pristine ng-valid ng-touched" data-ng-model="account.accountType" data-ng-options="opt.code as opt.description for opt in bankPersonCtrl.catalogs.bank.bankAccountTypes"><option value="" disabled="" selected="" class="">Seleccione</option><option value="0" selected="selected" label="Ahorros">Ahorros</option><option value="1" label="Corriente">Corriente</option></select>
正如您所注意到的,两者都具有相同的数据-ng-model =“account.accountType”,因此如果我尝试按模型制作选择器,我就不能。
我已经读过可以通过css创建一个选择器,但我不知道该怎么做。
您有什么建议可以解决这个问题吗?
答案 0 :(得分:1)
我必须得到by.repeater元素,所以这对我来说是正确的:
function getBankAccountElement(index, name, isSpouse){
if (typeof isSpouse === 'undefined'){
isSpouse = false;
}
var bankAccounts = element.all(by.repeater('account in bankPersonCtrl.analysisPerson.bankAccounts'));
if (isSpouse) {
var bankAccounts = element.all(by.repeater('account in bankPersonCtrl.analysisSpouse.bankAccounts'));
}
return bankAccounts.get(index).element(by.model('account.' + name));
}
我使用它的方式是:
this.getBankAccounts = function () {
return {
accountType: getBankAccountElement(0, 'accountType'),
accountNumber: getBankAccountElement(0, 'accountNumber'),
currentAverageAmmount: getBankAccountElement(0, 'currentAverageAmmount'),
previousAverageAmmount: getBankAccountElement(0, 'previousAverageAmmount'),
months: [getBankAccountElement(0, 'months[0]'), getBankAccountElement(0, 'months[1]'),
getBankAccountElement(0, 'months[2]')]
};
};