if语句添加ng-click

时间:2015-02-11 09:06:49

标签: angularjs ionic-framework ionic

我有Popover离子与一些列表(-Bills,-Education,-Medical,-Other),所有列表都有ng-click =" CloseInController()"。

但是我想要,只列出"其他"添加ng-click =" showListIns()",如果我点击"其他"任何弹出窗口都可以显示它。

这是我的Popover示例代码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();
};

 });
})

这是我的Popover代码:

<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>

任何人都可以帮助我?

提前致谢

1 个答案:

答案 0 :(得分:2)

只需为ng-click编写一个包装函数,并传递参数以选择应调用哪个函数。

<强> HTML

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

<强> CONTROLLER

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