【问题标题】:onsen notification to auto close after a set time设定时间后自动关闭的温泉通知
【发布时间】:2015-07-16 21:10:43
【问题描述】:

您好,我正在使用 Onsen 作为 AngularJS Phonegap/Cordova 项目的一部分。

我想知道是否可以在设定的时间后自动关闭温泉通知。也可以不包括按钮吗?

我当前的通知如下所示:

var notifyAutoClose = function(title, message) {
        var options = {
            title: title,
            message: message,
            buttonLabel: '', //Don't show button if possible
            animation: 'default'
        };
        ons.notification.alert(options);            
    }

如果不可能,那么在使用 AngularJS 时最好的非引导替代方案是什么。

非常感谢您的宝贵时间!

【问题讨论】:

    标签: angularjs cordova notifications onsen-ui auto-close


    【解决方案1】:

    您应该使用ons-dialog 指令创建一个自定义对话框。

    检查此代码(demo):

    //HTML
    <ons-page>
        <ons-toolbar>
          <div class="center">Dialog</div>
        </ons-toolbar>
        <ons-list ng-controller="DialogController">
          <ons-list-item ng-click="show('customdialog.html','Dialog title', 'it will close after 2 seconds')" modifier="tappable">
             Custom dialog
          </ons-list-item>
       </ons-list>
    </ons-page>
    
    <ons-template id="customdialog.html">
       <ons-dialog var="dialog" modifier="android">
         <ons-toolbar modifier="android">
           <div class="center">{{title}}</div>
         </ons-toolbar>
         <p style="text-align:center;margin-top:50px">{{message}}</p>
      </ons-dialog> 
     </ons-template>
    
    //JAVASCRIPT
    ons.bootstrap()
    .controller('DialogController', function($scope) {
       $scope.show = function(dlg,title,message) {
          $scope.title=title;
          $scope.message=message;
         ons.createDialog(dlg,{parentScope:$scope}).then(function(dialog) {
            dialog.show();
         });
         setTimeout(function(){dialog.hide()},2000)
       }
     });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多