2015-05-20 10 views
18

Sto usando $ ionicPopup.confirm() ma vorrei cambiare il testo del pulsante "cancella". È possibile farlo ?

io sappia .Show() sintassi:

buttons: [ 
    { text: 'Cancel' } 
    ] 

Ma non sembra funzionare con .Confirm() ...

Grazie 4 l'aiuto

risposta

9

UPDATE: il 1.0.0 ionico, questo è ora possibile (http://ionicframework.com/docs/api/service/ $ ionicPopup /)

Opzioni showConfirm:

{ 
    title: '', // String. The title of the popup. 
    cssClass: '', // String, The custom CSS class name 
    subTitle: '', // String (optional). The sub-title of the popup. 
    template: '', // String (optional). The html template to place in the popup body. 
    templateUrl: '', // String (optional). The URL of an html template to place in the popup body. 
    cancelText: '', // String (default: 'Cancel'). The text of the Cancel button. 
    cancelType: '', // String (default: 'button-default'). The type of the Cancel button. 
    okText: '', // String (default: 'OK'). The text of the OK button. 
    okType: '', // String (default: 'button-positive'). The type of the OK button. 
} 

Sì, è possibile fare wathever si desidera, utilizzando popup.show ionica e legare l'evento Annulla.

$ionicPopup.show({ 
    template: msg, 
    title: titleConfirm, 
    buttons: [ 
    { text: "BTN_NO", 
     onTap:function(e){ 
      return false; 
     } 
    }, 
    { text: "BTN_OK", 
     onTap:function(e){ 
      return true; 
     } 
    }, 
    ] 
}); 

Dopo un'indagine sul ionic popover.confirm function questo è non è possibile personalizzarlo. Il valore di popover.confirm sono hardcoded linea 446

function showConfirm(opts) { 
    return showPopup(extend({ 
     buttons: [{ 
     text: opts.cancelText || 'Cancel', 
     type: opts.cancelType || 'button-default', 
     onTap: function() { return false; } 
     }, { 
     text: opts.okText || 'OK', 
     type: opts.okType || 'button-positive', 
     onTap: function() { return true; } 
     }] 
    }, opts || {})); 
    } 
3

E 'possibile fare, è necessario utilizzare la cosa "tipo" all'interno del pulsante

buttons: [ 
      { text: 'Cancel' }, 
      { 
       text: '<b>Save</b>', 
       type: 'button-assertive', 
       onTap: function(e) { 
        $scope.request_form.abc = "accepted"; 
       } 
      } 
     ] 

nel tipo parte che si è necessario indicare il nome della classe e modificare il colore del pulsante.

+0

L'apertore ha chiesto un modo per personalizzare il testo del pulsante, non i colori. – baxeico

28

Almeno nella versione più recente di ionica (1.0.0) è possibile effettuare le seguenti operazioni:

var confirmPopup = $ionicPopup.confirm({ 
     title: 'Popup title', 
     template: 'Popup text', 
     cancelText: 'Custom cancel', 
     okText: 'Custom ok' 
    }).then(function(res) { 
     if (res) { 
      console.log('confirmed'); 
     } 
    }); 

Ecco il relative documentation.

Problemi correlati