Hey. Help deal with this feature.
function simpleService(){ this.name = "simpleService"; } angular.module('foo', []) .service('simpleService', simpleService); var myInjector = angular.injector(['foo']); var service = myInjector.get('simpleService'); alert(service.name); As far as I understood this thing gets services from the side of the module.
But in one of the projects I met the following:
controller('MyCtrl2', ['$scope', '$injector', function($scope, $injector) { require(['controllers/myctrl2'], function(myctrl2) { // injector method takes an array of modules as the first argument $injector.invoke(myctrl2, this, {'$scope': $scope}); } }) myctrl2.js
define([], function() { return ['$scope', '$http', function($scope, $http) { // You can access the scope of the controller from here $scope.welcomeMessage = 'hey this is myctrl2.js!'; // because this has happened asynchroneusly we've missed // Angular's initial call to $apply after the controller has been loaded // hence we need to explicityly call it at the end of our Controller constructor $scope.$apply(); }]; }); What are these tricks?