Component that adds "pull-to-refresh" to an
<script>
ons.bootstrap()
.controller('MyController', function($scope, $timeout) {
$scope.items = [3, 2 ,1];
$scope.load = function($done) {
$timeout(function() {
$scope.items.unshift($scope.items.length + 1);
$done();
}, 1000);
};
});
</script>
<ons-page ng-controller="MyController">
<ons-pull-hook var="loaded" ng-action="load($done)">
<span ng-switch="loader.getCurrentState()">
<span ng-switch-when="initial">Pull down to refresh</span>
<span ng-switch-when="preaction">Release to refresh</span>
<span ng-switch-when="action">Loading data. Please wait...</span>
</span>
</ons-pull-hook>
<ons-list>
<ons-list-item ng-repeat="item in items">
Item #{{ item }}
</ons-list-item>
</ons-list>
</ons-page>
See the Pen Alert, confirm and prompt dialogs by Onsen & Monaca (@onsen) on CodePen.
Name | Type Default Value |
Description |
---|---|---|
var | String | Variable name to refer this component. Optional |
disabled | If this attribute is set the "pull-to-refresh" functionality is disabled. Optional | |
ng-action | Expression |
Use to specify custom behavior when the page is pulled down. A $done function is available to tell the component that the action is completed.
Optional
|
on-action | Expression |
Same as ng-action but can be used without AngularJS. A function called done is available to call when action is complete.
Optional
|
height | String | Specify the height of the component. When pulled down further than this value it will switch to the "preaction" state. The default value is "64px". Optional |
threshold-height | String | Specify the threshold height. The component automatically switches to the "action" state when pulled further than this value. The default value is "96px". A negative value or a value less than the height will disable this property. Optional |
ons-changestate | Expression | Allows you to specify custom behavior when the "changestate" event is fired. Optional |
Signature | Description |
---|---|
setDisabled(disabled) | Disable or enable the component. |
isDisabled() | Returns whether the component is disabled or enabled. |
setHeight(height) | Specify the height. |
setThresholdHeight(thresholdHeight) | Specify the threshold height. |
on(eventName, listener) | Add an event listener. |
once(eventName, listener) | Add an event listener that's only triggered once. |
off(eventName, [listener]) | Remove an event listener. If the listener is not specified all listeners for the event type will be removed. |
Name | Description |
---|---|
changestate | Fired when the state is changed. The state can be either "initial", "preaction" or "action". |
Disable or enable the component.
Name | Type | Description |
---|---|---|
disabled | Boolean | If true the pull hook will be disabled. |
Returns whether the component is disabled or enabled.
Returns: true if the pull hook is disabled.
Specify the height.
Name | Type | Description |
---|---|---|
height | Number | Desired height. |
Specify the threshold height.
Name | Type | Description |
---|---|---|
thresholdHeight | Number | Desired threshold height. |
Add an event listener.
Name | Type | Description |
---|---|---|
eventName | String | Name of the event. |
listener | Function | Function to execute when the event is triggered. |
Add an event listener that's only triggered once.
Name | Type | Description |
---|---|---|
eventName | String | Name of the event. |
listener | Function | Function to execute when the event is triggered. |
Remove an event listener. If the listener is not specified all listeners for the event type will be removed.
Name | Type | Description |
---|---|---|
eventName | String | Name of the event. |
listener | Function | Function to execute when the event is triggered. |
Fired when the state is changed. The state can be either "initial", "preaction" or "action".
Name | Type | Description |
---|---|---|
event | Object | Event object. |
event.pullHook | Object | Component object. |
event.state | String | Current state. |