2015-02-11 67 views
0

我有Popover離子與一些列表(-Bills,-Education,-Medical,-Other),並且所有列表都有ng-click =「CloseInController()」。if語句添加ng-click

但我想,只列出「其他」添加ng-click =「showListIns()」,所以如果我點擊「其他」任何彈出窗口來顯示它。

這是我的示例代碼app.js爲酥料餅:

.controller('PopOver', function($scope, $ionicPlatform, $ionicPopover, Category, Expense) { 


Category.all('D').then(function(res) { 
    console.log(res); 
    console.log("inilah " + res.length); 
    if (res.length > 0) { 
     $scope.ListCategory = res; 
    } else { 
     var cat = {}; 
     cat.Type = 'D'; 
     cat.Name = 'Bills'; 
     Category.add(cat); 
     cat.Name = 'Education'; 
     Category.add(cat); 
     cat.Name = 'Entertainment'; 
     Category.add(cat); 
     cat.Name = 'Food and Drink'; 
     Category.add(cat); 
     cat.Name = 'Medical'; 
     Category.add(cat); 
     cat.Name = 'Shopping'; 
     Category.add(cat); 
     cat.Name = 'Travel'; 
     Category.add(cat); 
     cat.Name = 'Other'; 

     Category.add(cat).then(function(res) { 
      window.location.reload(); 
     }); 
    } 
}) 

$scope.showPopover = function($event, index, ExpenseId) 
{ 
    //console.log(ExpenseId); 
$scope.index = index; 
$scope.ItemId = ExpenseId; 
/* $scope.index = index; */ 
$scope.popover.show($event); 
} 

$scope.closeInController = function(selectedItem, ExpenseId) { 

    Expense.updateCategory(selectedItem, ExpenseId); 
    $scope.popover.hide(); 
}; 

}); 
}) 

,這對我的代碼酥料餅:

<ion-popover-view> 
<ion-content> 
<div id="popup"> 
<ion-scroll style="height: 150px;"> 
    <label ng-repeat="item in ListCategory" for="{{item.Name}}"> 
    <input type="radio" 
      ng-model="my.favorite" 
      ng-value="item.Name" 
      ng-click="closeInController(item.CategoryId, ItemId)" 
      id="{{item.CategoryId}}" 
      name="category"> 
    {{item.Name}} 
    <br> 
    </label> 
    </ion-scroll> 

    </div> 
</ion-content> 
</ion-popover-view> 

任何人都可以幫我嗎?

在此先感謝

回答

2

只寫一個包裝函數爲您ng-click並通過參數來選擇哪個函數被調用。

HTML

ng-click="wrapperFunc('showListIns', param1, param2)" 

控制器

$scope.wrapperFunc = function(functionName){ 
    if(functionName === 'showListIns') showListIns(param1, param2); 
    else if (functionName === 'closeInController') closeInController(param1, param2); 
} 
+0

奧凱,我來試試.. :) – 2015-02-12 03:12:38