【问题标题】:How to declare an AngularJs service with no parameters?如何声明没有参数的 AngularJs 服务?
【发布时间】:2020-11-09 08:57:20
【问题描述】:

这行得通:

'use strict';

angular.module('MyApp').service('searchControllerPersistentData', ['$state', function ($state) 
{
    const Self = this;
}]);

但这会在我尝试注入服务的控制器中出现错误:

'use strict';

angular.module('MyApp').service('searchControllerPersistentData', ['', function () 
{
    const Self = this;
}]);

服务不需要注入任何东西。如何申报?

【问题讨论】:

    标签: angularjs angularjs-service


    【解决方案1】:

    去掉括号即可:

    angular.module('MyApp').service('searchControllerPersistentData', function () 
    {
        const Self = this;
    });
    
    

    【讨论】:

    • 天啊! :-) 谢谢你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    相关资源
    最近更新 更多