如何在离子中运行后台服务?

时间:2016-06-16 07:34:16

标签: angularjs ionic-framework

我希望在应用启动时启动后台服务,重启后服务会自动启动

document.addEventListener('deviceready', function() {
   myService = cordova.plugins.myService;;
  upload();
},

TRUE);

1 个答案:

答案 0 :(得分:0)

您需要将此服务注入您的控制器

.controller('myCtl', myCtl);

function myCtl(LoginService) {

   $scope.username = null;
   $scope.password = null; 

   $scope.doLogin = LoginService.loginUser;

}

然后在你的视图中

<div ng-controller="myCtl">
   ...

   <input type="text" ng-model="username">
   <input type="password" ng-model="password">

   <button type="button" ng-click="doLogin(username, password)">
      Login
   </button>

   ...
</div>