代码之家  ›  专栏  ›  技术社区  ›  Mawg says reinstate Monica

如何声明一个没有参数的AngularJs服务?

  •  0
  • Mawg says reinstate Monica  · 技术社区  · 5 年前

    这是有效的:

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

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

    这项服务不需要注入任何东西。我怎么申报?

    0 回复  |  直到 5 年前
        1
  •  1
  •   Bill P Nelson Bassey    5 年前

    只需拆下支架:

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