无法使用Ionicframework显示Toast消息

Saa*_*dia 1 toast angularjs cordova ionic-framework

我对移动开发领域非常陌生,并且正在使用ionic框架。

我要做的就是通过遵循本教程向用户显示敬酒消息到目前为止,我仍然在疯狂尝试实现它。

我得到的错误如下

无法读取未定义的属性“ toast”

  1. 我已经安装科尔多瓦
  2. 我已经安装了Toast插件

在我的index.html中,我添加了脚本 ng-cordova.min.js

  <script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
  <!-- cordova script (this will be a 404 during development) -->
  <script src="cordova.js"></script>
Run Code Online (Sandbox Code Playgroud)

我需要添加 Toast.js在index.html中文件吗?如果是,那将无济于事,并导致另一个错误。

这是我的控制器

  .controller('UsersController', ['$scope', '$http', '$cordovaToast', function ($scope, $http, $cordovaToast) {

    $scope.showToast = function() {
      $cordovaToast
        .show("Here's a message", 'short', 'center')
        .then(function(success) {
          console.log('Success');
        }, function (error) {
          console.log('Error');
        });
    };
  }
  ]);
Run Code Online (Sandbox Code Playgroud)

我在这里想念什么?

我将非常感谢您的帮助。

更新

由@Del建议进行更改后,出现以下错误

ionic.bundle.js:25642 Error: [$injector:unpr] Unknown provider: $cordovaToastProvider <- $cordovaToast <- UsersController
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=%24cordovaToastProvider%20%3C-%20%24cordovaToast%20%3C-%20UsersController
    at ionic.bundle.js:13380
    at ionic.bundle.js:17574
    at Object.getService [as get] (ionic.bundle.js:17721)
    at ionic.bundle.js:17579
    at getService (ionic.bundle.js:17721)
    at invoke (ionic.bundle.js:17753)
    at Object.instantiate (ionic.bundle.js:17770)
    at ionic.bundle.js:22326
    at self.appendViewElement (ionic.bundle.js:56883)
    at Object.switcher.render (ionic.bundle.js:54995)
Run Code Online (Sandbox Code Playgroud)

Del*_*Del 5

如果正确安装了该插件,则无需使用$ cordovaToast就可以使用它

.controller('UsersController', ['$scope', '$http', function ($scope, $http) {

    $scope.showToast = function() {
      window.plugins.toast
        .show("Here's a message", 'short', 'center')
        .then(function(success) {
          console.log('Success');
        }, function (error) {
          console.log('Error');
        });
    };
  }
  ]);
Run Code Online (Sandbox Code Playgroud)

您不必添加ng-cordova或toast.js。

如果添加插件(ionic插件添加...),请删除平台,再次添加并构建,它应该可以工作