I have the following code, and added the reset function that I would like to use from ng-click at any place in any template.
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
});
$ionicPlatform.reset = function(path) {
console.log("hello")
// $location.path( path );
};
})
In index.html im trying to use it, but nothing happens.
<ion-nav-bar class="bar-stable nav-title-slide-ios7">
<ion-nav-back-button class="button-icon icon ion-ios7-arrow-back">
Back
</ion-nav-back-button>
<ion-nav-buttons side="right">
<button class="button button-clear button-positive" ng-click="reset()">
Refresh
</button>
</ion-nav-buttons>
</ion-nav-bar>
Am I doing this wrong? Or how do you get a function available in all controllers?
How about wrapping ion-nav-bar
inside a div with a controller and using factory.
var app = angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']);
app.factory('ResetService', function(){
var reset = function(path){
console.log('hello');
};
return reset;
});
Now you inject this factory in the controller you created controller. Good luck!