Created
September 8, 2016 13:58
-
-
Save sparrow/90cb5583da780c6377a2c03d0c90252c to your computer and use it in GitHub Desktop.
This is an AngularJS code snippet that we used for our blog post https://rubygarage.org/blog/react-vs-angularjs at RubyGarage. It demonstrates how we inject dependencies in an AngularJS module using an $inject property. This code snippet was taken from a well-known TodoMVC application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// an example from GitHub | |
angular.module('todomvc') | |
.controller('TodoCtrl', TodoCtrl); | |
function TodoCtrl(s, r, f, a) { | |
'use strict'; | |
var todos = s.todos = a.todos; | |
s.newTodo = ''; | |
s.editedTodo = null; | |
// missing function code is omitted for brevity | |
}; | |
//inject dependencies using a special function | |
TodoCtrl[“inject”] = [“$scope”, “$routeParams”, “$filter”, “store”]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment