首先,對於可怕的標題感到抱歉。我可以在這裏解釋清楚。在ng-repeat中的2個不同的div上單擊2 ng不起作用
我有2個div在ng-repeat中,我想在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>
發表您的控制器 – Sajeetharan
@Sajeetharan增加。請立即檢查。 –
我沒有看到任何問題 – Sajeetharan