Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 1.06 KB

dependency-injection.md

File metadata and controls

38 lines (28 loc) · 1.06 KB

I need you

Dependency Injection

One key aspect of Angular as a framework is how it relies on dependency injection. There are few places you need to "inject" dependencies:

The index.html:

<!-- Angular Packages -->
<script src="vendors/angular-ui-router.min.js"></script>
<script src="vendors/ngStorage.min.js"></script>
<script src="vendors/angular-cookies.min.js"></script>

The Angular Module:

angular
    .module('app', [
        'ui.router',
        'ngStorage',
        'ngCookies'
    ])

Functions of the module:

.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider){ }]);

Note: that the order of your dependecy injections must be the same as the order of the function parameters! 💥

Dependency injection allows Angular to be modular and makes your code cleaner and pluggable :)


Prev: Directory Structure | Next: States | Home: Lecture Outline