我使用的是角度x-editable,我的代码如下
<li ng-repeat="emailId in emailDetails">
<img class="permission"
ng-src="assets/images/profile-ima.jpg"
editable-select="emailId.privacy_type"
e-form="rowform"
e-name="privacy_type"
e-ng-options="q.privacy_id as q.privacy_type for q in privacyTypes">
</img>
<div class="pfDetails"
editable-text="emailId.email"
e-form="rowform"
e-name="email"
ng-click="rowform.$show()"
onbeforesave="checkEmail($data)">
{{ emailId.email || 'Edit' }}
</div>
<div class="addIcon" ng-click="addEmail()"></div>
</li>
单击.pfDetails
div编辑选项将启用。我可以更改那个没问题的emailid。 .addIcon
div可以添加更多字段。
我的问题是如何为每个新div更改.permission
字段ng-src
。如果我因为相同的类名更改了它在所有新img字段中反映的值。
有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
这个代码太少,无法提供更多猜测答案。
我通常使用这种方法:
<img ng-if"emailId.privacy_type=='a'" class="permission"
ng-src="assets/images/profile-ima.jpg"
editable-select="emailId.privacy_type"
e-form="rowform"
e-name="privacy_type"
e-ng-options="q.privacy_id as q.privacy_type for q in privacyTypes">
</img>
<img ng-if"emailId.privacy_type=='b'" class="permission"
ng-src="assets/images/profile-imb.jpg"
editable-select="emailId.privacy_type"
e-form="rowform"
e-name="privacy_type"
e-ng-options="q.privacy_id as q.privacy_type for q in privacyTypes">
</img>
依此类推......
更好的方法是为图像命名,使其与隐私类型部分匹配:
<img class="permission"
ng-src="assets/images/profile-im{{emailId.privacy_type}}.jpg"
editable-select="emailId.privacy_type"
e-form="rowform"
e-name="privacy_type"
e-ng-options="q.privacy_id as q.privacy_type for q in privacyTypes">
</img>
所以:
当privacy_type ='a'ng-src将是profile-ima.jpg
当privacy_type ='b'ng-src将是profile-imb.jpg
但那只是猜测,因为我不知道你的数据。