Angular Toast在我的服务中不起作用

Angular-Toaster not working in my service?

本文关键字:不起作用 服务 我的 Toast Angular      更新时间:2023-09-26

我已经从这个网站了解了tover.js,并试图在我的web应用程序中实现它。我已经按照这个例子做了,但不起作用。

这是我实现的服务:

function () {
    angular
        .module('FoursquareApp')
        .factory('DataService', DataService);
    DataService.$inject = ['$http','toaster'];
    function DataService($http, toaster) {
        .id,
                venueName: venue.name,var serviceBase = '/api/places/';
        var placesDataFactory = {};
        var userInContext = null;
        var _getUserInCtx = function () {
            return userInContext;
        };
        var _setUserInCtx = function (userInCtx) {
            userInContext = userInCtx;
        };
        var _savePlace = function (venue) {
            //process venue to take needed properties
            var minVenue = {
                userName: userInContext,
                venueID: venue
                address: venue.location.address,
                category: venue.categories[0].shortName,
                rating: venue.rating
            };
            return $http.post(serviceBase, minVenue).then(
                function (results) {
                    toaster.pop('success', "Bookmarked Successfully", "Place saved to your bookmark!");
                },
                function (results) {
                    if (results.status == 304) {
                        toaster.pop('note', "Faield to Bookmark", "Something went wrong while saving :-(");
                    }
                    else {
                        toaster.pop('error', "Failed to Bookmark", "Something went wrong while saving :-(");
                    }
                    return results;
                });
        };

我已经调用了index.html中的库脚本和css文件。

你知道我可能做错了什么吗?

您确定使用toaster.js库吗?流行的是toastr.js

尝试将您的代码修改为

DataService.$inject = ['$http','toastr'];
function DataService($http, toastr) {
...

还要确保在index.html中链接这个js文件,并在主应用程序模块定义中将这个包作为第二个(依赖)参数