gpt4 book ai didi

angularjs - Angular ngToast 不显示

转载 作者:行者123 更新时间:2023-12-05 07:42:09 24 4
gpt4 key购买 nike

我在 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 Controller 中(我在 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")<br/>
@Scripts.Render("~/bundles/angular")<br/>
//other scripts

最佳答案

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

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

只有在注入(inject)正确的情况下才能使其正常工作。

关于angularjs - Angular ngToast 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44780095/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com