2016-12-01 8 views
0

我有一個插件按鈕元素如何正確調用OnsenUI版本1中的ons按鈕上的startSpinner()?

<ons-button modifier="large--cta" ng-click="login($event, input.email, input.password)">Log In</ons-button>

和一個函數(登錄)正在嘗試使用OnsenUI的附件按鈕的startSpinner()方法來啓動一個微調按鈕顯示該應用正在處理他們的請求的用戶。

我試過以下沒有成功。每個控制檯都沒有定義這些功能。

event.currentTarget.startSpinner()

event.target.startSpinner()

startSpinner(event.currentTarget)

我該如何去有關從通過NG單擊調用的函數啓動按鈕上的微調?

回答

0

你需要做的首先是如下定義服務:

app.factory('service', ['$rootScope', function($rootScope) { 
    return { 
    showSpinnerAuto : function() { 
     modal.show(); 
     setTimeout('modal.hide()', 10000); 
    }, 
    showSpinnerTimer : function(timer) { 
     modal.show(); 
     setTimeout('modal.hide()', timer); 
    }, 
    showSpinner : function() { 
     modal.show(); 
    }, 
    hideSpinner : function() { 
     modal.hide(); 
    } 
    }; 

}]); 

您還需要在您的視圖定義微調模型如下:

<ons-modal var="modal"> 
    <i class="fa fa-spinner fa-spin fa-pulse"></i> 
    <br><br>loading... 
</ons-modal> 

最後,你可以請在您的控制器中顯示/隱藏Spinner,如下所示:

app.controller('Controller', ['$rootScope', '$scope', 'service', function($rootScope, $scope, service) { 
    service.showSpinner(); //show 
    service.hideSpinner(); //hide 
    service.showSpinnerAuto(); //show and then hide automatically 
}]); 

希望得到這種幫助!

相關問題