首先,抱歉这个可怕的头衔。我可以在这里解释一下。
我在ng-repeat中有2个div,我想在2个不同的div上调用2个不同的函数,但由于某种原因,只有第二个div的ng-click有效,请参阅下面的代码。
var app = angular.module("myApp", []);
app.controller("ContactListController", getUserContacts);
function getUserContacts($scope) {
$scope.contacts = [{
'name': 'abc',
'phone': '123',
'call_rate': 50,
'exchange_currency_name': 67
}, {
'name': 'xyz',
'phone': '345',
'call_rate': 20,
'exchange_currency_name': 67
}]
$scope.setcontact = function(x) {
alert("setContact");
}
$scope.DialCallfromHome = function(x) {
alert("dial");
}
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<ons-list ng-app="myApp" ng-controller="ContactListController">
<input type="search" ng-model="search" class="search-input" style="width:95%; margin: 6px auto 6px auto;" placeholder="Search">
<div ng-show="loading" id="loadingDiv">
<img src="images/loader-logo.png" alt="">
<div id="loader"></div>
</div>
<ons-list-item modifier="chevron" class="list-item-container" ng-repeat="x in contacts| filter:search">
<div class="list-item-left" ng-click="DialCallfromHome(x);">
<div class="initial">
<img src="images/call-icon.png" style="width: 40px; margin: 5px;"></img>
</div>
</div>
<div class="list-item-right" ng-click="setcontact(x);">
<div class="list-item-content">
<div class="name">{{x.name}}
<br />
<span class="number">{{x.phone}}</span>
<span class="lucent">Call for {{x.call_rate}}¢/min</span>
</div>
<span class="desc">$1 = {{x.exchange_rate}} {{x.exchange_currency_name}}</span>
</div>
</div>
</ons-list-item>
<br>
<div ng-show="contacts.length == 0" style="width:95%; margin: 6px auto 6px auto;">No contacts added yet.</div>
</ons-list>
答案 0 :(得分:2)
在HTML代码中添加z-index
属性。这将使你的前进。
在这里做什么:
<div class="list-item-left" ng-click="DialCallfromHome(x);" style="z-index:1;">
答案 1 :(得分:0)
这是工作示例
var app = angular.module("myApp", []);
app.controller("ContactListController", getUserContacts);
function getUserContacts($scope) {
$scope.contacts = [{
'name': 'abc',
'phone': '123',
'call_rate': 50,
'exchange_currency_name': 67
}, {
'name': 'xyz',
'phone': '345',
'call_rate': 20,
'exchange_currency_name': 67
}]
$scope.DialCallfromHome = function(n) {
alert("dial");
}
$scope.setcontact = function(n) {
alert("setcontact");
}
};
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<ons-list ng-app="myApp" ng-controller="ContactListController">
<input type="search" ng-model="search" class="search-input" style="width:95%; margin: 6px auto 6px auto;" placeholder="Search">
<div ng-show="loading" id="loadingDiv">
<img src="images/loader-logo.png" alt="">
<div id="loader"></div>
</div>
<ons-list-item modifier="chevron" class="list-item-container" ng-repeat="x in contacts| filter:search">
<div class="list-item-left" ng-click="DialCallfromHome(x);">
<div class="initial">
<img src="" alternate="Phone Icon" style="width: 40px; margin: 5px;"></img>
</div>
</div>
<div class="list-item-right" ng-click="setcontact(x);">
<div class="list-item-content">
<div class="name">{{x.name}}
<br />
<span class="number">{{x.phone}}</span>
<span class="lucent">Call for {{x.call_rate}}¢/min</span>
</div>
<span class="desc">$1 = {{x.exchange_rate}} {{x.exchange_currency_name}}</span>
</div>
</div>
</ons-list-item>
<br>
<div ng-show="contacts.length == 0" style="width:95%; margin: 6px auto 6px auto;">No contacts added yet.</div>
</ons-list>
&#13;