离子空白项目弹出消息问题

时间:2016-10-22 02:44:15

标签: ionic-framework ionicpopup

根据我的要求,我想在打开应用程序时显示一条弹出消息。不能使用警报。



$query = "INSERT INTO BbUsers(u_username,u_passhash,u_emailaddr,u_validate) VALUES(?,?,?,?)";
$refArr = array("ssss", $username, $passhash, $email, $vaildHash); 
$result = cleanQuery($query, $refArr);

if ($result2) {
    sendEmail($email, $hash);
} else {
    echo "OOps   something went wrong plz try again";
 exit;
}




但这是一个错误" $ scope未定义"。

2 个答案:

答案 0 :(得分:2)

运行函数中未提供

$scope。因此,您只能注入$rootScope来运行函数。将$scope替换为$rootScope,您就可以了。

.run(function($ionicPlatform, $rootScope, $ionicPopup, $timeout) {
    $ionicPlatform.ready(function() {

    // Code here
    ....

    $rootScope.showAlert = function() {
       var alertPopup = $ionicPopup.alert({
         title: 'Don\'t eat that!',
         template: 'It might taste good'
       });

       alertPopup.then(function(res) {
         console.log('Thank you for not eating my delicious ice cream cone');
       });
    };

    // Code here
    ....
});

<button ng-click="$root.showAlert()">

答案 1 :(得分:1)

angular.module('starter', ['ionic'])

.run(function($ionicPlatform, $rootScope, $ionicPopup, $timeout) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }

     $rootScope.showAlert = function() {
       var alertPopup = $ionicPopup.alert({
         title: 'Don\'t eat that!',
         template: 'It might taste good'
       });

       alertPopup.then(function(res) {
         console.log('Thank you for not eating my delicious ice cream cone');
       });
    };

    if (window.cordova) {
        cordova.plugins.diagnostic.isLocationEnabled(function(enabled) {
            if(!enabled){
                alert("Location is not enabled");
                cordova.plugins.diagnostic.switchToLocationSettings();
            }
        }, function(error) {
            alert("The following error occurred: " + error);
        });
    }
  });
})

我对您的代码进行了一些更改。希望这能帮助您解决问题。