1

我正在进行我的第一个大型离子项目并且被卡住了。有人知道如何在离子弹出窗口中动态隐藏和显示按钮吗?我需要最初隐藏按钮,但是在发生某些事情后,按钮应该会显示出来。知道如何完成吗?

为了进一步解释,这里需要在 $ionicPopup 按钮内提供角度指令。例如

 buttons: [{
            text: 'Cancel'
        }, {
            text: '<b ng-disabled="user.length<1">Delete</b>',
            type: 'button-crimson'
    }]

但是ng-disabled="user.length<1"在呈现弹出窗口时会被修剪。

4

3 回答 3

1

如果你还在寻找这个问题的答案...

我为我的按钮数组创建了一个变量

var buttons = [{...}, {...}]

然后将其分配给弹出窗口中的对象

$ionicPopup.show({
    templateUrl: 'templates/pop-up.html',
    title: 'My Popup',
    subTitle: 'stuff,
    scope: $scope,
    **buttons: buttons,**

然后会改变那个数组

buttons.splice(0, 1, {/*new button*/})

尚未对其进行测试,但如果您想编辑标题或课程,它也可能有效

buttons[0].type = 'newCssClass';
于 2018-02-07T02:51:36.427 回答
0

我的解决方法是将动态按钮放在弹出窗口的模板中,而不是按钮数组中。这并不理想,但它会起作用。

例如:

addPopup = $ionicPopup.show({
        templateUrl: 'templates/pop-up.html',
        title: 'My Popup',
        subTitle: 'stuff,
        scope: $scope,
        buttons: [{
                text: 'Cancel',

然后在 pop-up.html 中,您可以像往常一样执行通常的 angular ng-if/ng-hide/ng-disabled/etc 操作。缺点是这些按钮不会出现在数组中按钮所在的底部,但是通过一些样式工作,您可以使它看起来仍然不错。

于 2016-08-16T15:10:13.903 回答
-1

使用 $scope 变量和 ng-hide/ng-show 应该很容易

function something_happens(){
  $scope.it_happened = true;
}

<button ng-show="it_happened">Qlik Me</button>

仅当 $scope.it_happened == true 时才会显示该按钮

于 2016-01-08T18:53:55.457 回答