Angular-Toaster不能在我的服务中工作?

时间:2015-12-09 09:04:57

标签: javascript angularjs

我必须从这个site了解toaster.js并尝试在我的网络应用程序中实现它。我已根据示例完成了它,但它不起作用。

这是我实施的服务:

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文件。

我可能做错了什么想法?

1 个答案:

答案 0 :(得分:0)

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

尝试将代码修改为

DataService.$inject = ['$http','toastr'];

function DataService($http, toastr) {
...

同时确保您在index.html中链接此js文件,并在主应用程序模块定义中将此包引用为第二个(依赖项)参数