Search code examples
javascriptcordovaionic-frameworkngcordova

Ionic $cordovaDialogs Beep


I need for my Ionic Reminder App some kind of audio notification and I think the CordovaDialogs Beep function could do the trick.

The only problem is when I try to execute it I got the famous error :

TypeError: Cannot read property 'beep' of undefined

It's crazy because the alert, prompt and confirm functions work flawlessly on my browser ... and yes I did update the ngCordova to last version so I can play with it on my browser.

The code I try to run is as simple as that :

.controller('statusCtrl', function($scope, $rootScope, $cordovaDialogs) {

  $cordovaDialogs.beep(3);

})

If I try to console the $cordovaDialogs Object in the controller I can clearly see the beep function.

Thanks.


Solution

  • Actually added some things in the controller ($ionicPlatform etc) and managed to make working on the device. On browser vibrate and beep doesn't work and I am ok with that except the console errors.

    .controller('statusCtrl', function($scope, $cordovaDevice, $ionicPlatform, $cordovaVibration,$cordovaDialogs) {
        $ionicPlatform.ready(function() {
            $scope.$apply(function() {
    
              // getting device infor from $cordovaDevice
              var device = $cordovaDevice.getDevice();
    
              $scope.manufacturer = device.manufacturer;
              $scope.model = device.model;
              $scope.platform = device.platform;
              $scope.uuid = device.uuid;
              $cordovaVibration.vibrate(100);
              $cordovaDialogs.beep(3);
    
            });
    
        });
    
    })