在离子Angularjs中设置全局函数

时间:2014-08-08 13:55:26

标签: javascript angularjs ionic-framework

我有以下代码,并在任何模板的任何位置添加了我想要使用ng-click的重置功能。<​​/ p>

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 );
  };
})

在我试图使用它的index.html中,但没有任何反应。

<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>

我这样做错了吗?或者如何在所有控制器中获得功能?

1 个答案:

答案 0 :(得分:1)

如何使用控制器和使用工厂将ion-nav-bar包装在div中。

var app = angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']);

app.factory('ResetService', function(){
    var reset = function(path){
      console.log('hello');
    };

    return reset;
});

现在您将此工厂注入您创建控制器的控制器中。祝你好运!

相关问题