【问题标题】:LxNotificationService service not working in AngularJS appLxNotificationService 服务在 AngularJS 应用程序中不起作用
【发布时间】:2015-02-19 13:53:12
【问题描述】:

我最近开始使用 AngularJS 和 Lumx。我尝试添加可以在网站上的“通知”选项卡下找到的通知。 Link is here.

任何人,我得到的错误是

“错误:LxNotificationService 未定义”

所以我将它添加到控制器中的服务列表中。

下面是我的 app.js 文件

var testing = angular.module('testing', []);

testing.controller('mainCtrl', function ($scope){

$scope.notify = function(type)
{
    if (type === 'simple')
    {
        LxNotificationService.notify('Lorem Ipsum');
    }
    else if (type === 'sticky')
    {
        LxNotificationService.notify('Lorem Ipsum', undefined, true);
    }
    else if (type === 'icon')
    {
        LxNotificationService.notify('Lorem Ipsum', 'android');
    }
    else if (type === 'color')
    {
        LxNotificationService.notify('Lorem Ipsum', undefined, false, 'grey');
    }
    else if (type === 'info')
    {
        LxNotificationService.info('Lorem Ipsum');
    }
    else if (type === 'success')
    {
        LxNotificationService.success('Lorem Ipsum');
    }
    else if (type === 'warning')
    {
        LxNotificationService.warning('Lorem Ipsum');
    }
    else if (type === 'error')
    {
        LxNotificationService.error('Lorem Ipsum');
    }
};

});

html 页面上的一切都运行良好,我认为我只是没有正确调用该服务。有人可以帮忙吗?

附言

下面是我所有脚本文件的列表。

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/velocity/velocity.js"></script>
<script src="bower_components/moment/min/moment-with-locales.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/lumx/dist/lumx.min.js"></script>
<script src="app.js"></script>

提前谢谢你,尼尔

【问题讨论】:

    标签: angularjs lumx


    【解决方案1】:

    您在定义 testing 模块时忘记指定 lumx 模块依赖项:

    angular.module('testing', ['lumx']);

    你也忘了在你的控制器中注入LxNotificationService

    angular.module('testing').controller('mainCtrl', [
      '$scope',
      'LxNotificationService',
    function ($scope, LxNotificationService) {
      ... your code here ...
    }
    

    【讨论】:

      【解决方案2】:

      不是 100%,因为我是 LumX 的新手,但看起来您缺少 LumX 模块的依赖项

      var app = angular.module('myApp', ['lumx']);
      

      巴里

      【讨论】:

        猜你喜欢
        • 2015-03-11
        • 2016-11-23
        • 2023-03-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多