angularjs

时间:2016-03-14 13:45:26

标签: javascript html angularjs ionic-framework

我是angularjs的新手和单位转换器的演示应用程序,我有2个html页面和一个控制器,在我的控制器中我已经采取了一个变量并在函数中使用它,我为它赋值,在那个fubction里面我得到了它的完美价值但在它之外我得到了null.my代码如下:

JS

var db = null;
 var live=[];
   var getvaluesbtn = null;
   var val = null;
var example = angular.module('starter', ['ionic', 'ngCordova'])

example.run(function($ionicPlatform, $cordovaSQLite, $rootScope, $q) {
var dfd = $q.defer();

    $rootScope.deviceReady = dfd.promise;
    $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) {
            StatusBar.styleDefault();
        }
db = window.sqlitePlugin.openDatabase({name: "Converter.sqlite"});
console.log("database path:: " , db);
 dfd.resolve( device );
  }
  );
}
)



example.controller("ExampleController",
function($rootScope, $scope, $cordovaSQLite, $location){

 $rootScope.deviceReady.then(function( device ){
 $scope.items =[];
  var querybtnlist= "SELECT name,fk_category FROM category where fk_category="+ 0;
  $cordovaSQLite.execute(db, querybtnlist).then(function(resultbtnlist) {
                  if(resultbtnlist.rows.length > 0) {


                     for (var i=0; i<resultbtnlist.rows.length; i++) {

                  var btnname = resultbtnlist.rows.item(i).name;
                  var btnid = resultbtnlist.rows.item(i).fk_category;
                $scope.items.push({buttonID: btnid , buttonname: btnname});
                  }
   } else {
                      alert("No results found");
                      console.log("No results found");
                  }
              }, function (err) {
                  alert(err);
                  console.error(err);
              }
              );

 $scope.redirect = function(){

 window.location = "index.html";

   }

$scope.getResult = function($index, item) {

    $rootScope.indexResult = $scope.items[$index];
      getvaluesbtn= $scope.indexResult.buttonID;
val = getvaluesbtn;
//alert(getvaluesbtn);
window.location = "convertpath.html";

  };

  alert(val);

0 个答案:

没有答案