Computer Science

Question

Difference between dependency injection between array and without array angular

1 Answer

  • Reading angular docs on dependency injection, there are two minification-friendly methods to do this:

    Inline Array Annotation:

    module.factory("MyStuff",['dependency',function(dep){...}])

    The $inject property:

    function MyStuff(dep) {...}

    MyStuff.$inject = ['dependency'];

    module.factory("MyStuff",MyStuff);

    The inline one (first) is recommended. In one of my projects the style guide insists on the use of $inject property. I also see $inject property form quite often in open source code.

You May Be Interested