Привет. Помогите разобратся с данной функцией.
function simpleService(){
this.name = "simpleService";
}
angular.module('foo', [])
.service('simpleService', simpleService);
var myInjector = angular.injector(['foo']);
var service = myInjector.get('simpleService');
alert(service.name);
Насколько я понял эта штука получает сервисы со сторонего модуля.
Но в одном с проэктов я встретил следующее :
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();
}];
});
Что это за приемы?