【问题标题】:Angular ngToast not showingAngular ngToast 未显示
【发布时间】:2017-06-27 12:16:51
【问题描述】:

我在 asp.net mvc 应用程序中有一个 Angular 应用程序。我无法让 ngToast 工作。没有显示 toast 消息,我没有看到任何错误。提前感谢您的帮助。

BundleConfig.cs

//angular scripts
        bundles.Add(new ScriptBundle("~/bundles/angular").Include(
          "~/Scripts/angular.js",
          "~/Scripts/angular-route.js",
          "~/Scripts/angular-animate.js",
          "~/Scripts/angular-sanitize.js",
          "~/Scripts/ngmodules/angular-modal-service.js",
          "~/Scripts/modules/ngToast.js",
          "~/Scripts/i18n/angular-locale_el-GR.js",
          "~/Scripts/ngmodules/ng-qtip2.js",
          "~/Scripts/ngmodules/ng-lodash.js",
          "~/Scripts/angular-summernote.min.js"
          ));
          bundles.Add(new StyleBundle("~/plugins/ngtoast").Include(
                "~/Content/plugins/ngToast/ngToast.css"
          ));

Angular 应用:

 var app = angular.module('messagingApp', [
     // Angular modules 
       'ngAnimate',
       'ngRoute'
     // 3rd Party Modules
     , 'ngToast'
     , "angularModalService"
     , "summernote"

]);

在 ng 控制器中(我包含一个带有 ngToast.create() 的函数):

    (function () {
    "use strict";
    angular
        .module('messagingApp')
        .controller('messagecontroller', mController);

    mController.$inject = ['$scope', '$location', "$window", "$filter", "$routeParams", "$route", "$rootScope", "ngToast", "mService"];

    function mController($scope, $location, $window, $filter, $routeParams, $route, $rootScope, ngToast, mService) {

        //some functions    



        $scope.refreshMailbox = function () {
            mService.getMessagesCount().then(function (data) {
                $scope.inboxCount = data.CountInbox;
                $scope.sentCount = data.CountSent;
                if (data.CountNew > $scope.newCount) {
                    ngToast.create('You have new messages');                    
                }
                $scope.newCount = data.CountNew;
                $scope.importantCount = data.CountImportant;
            });

            mService.getInbox($scope.currentPage).then(function (data) {
                $scope.messages = data.Messages;
                $scope.currentPage = data.CurrentPage;
            });
        }

    };
})();

在我的cshtml文件末尾

@Styles.Render("~/plugins/ngtoast")
@Scripts.Render("~/bundles/angular")
//other scripts

【问题讨论】:

  • 您确定没有脚本错误吗?注射是否正常进行?上面的代码在我看来非常好。
  • 我遇到了同样的问题,控制台中没有错误,并且注入也发生了,因为调试器能够显示 ngToast 对象。

标签: angularjs ngtoast


【解决方案1】:

您需要使用 ngToast 配置才能使其工作。

ngToast.configure({
     verticalPosition: 'top',
     horizontalPosition: 'right',
     maxNumber: 3,
     dismissButton: true,
     timeout: 3000
});

只有在注入正确的情况下才能使用类似的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    相关资源
    最近更新 更多