Answer the question
In order to leave comments, you need to log in
Why service is not created?
<body ng-app="app">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>
<script src="jquery-2.1.4.min.js"></script>
<div ng-controller="MainController"></div>
<script>
var app = angular.module('app', []);
app.service('$myService', function(){
});
app.controller('MainController', ['$scope', function($scope, $myService){
console.log($myService); // почему $myService undefined?
}]);
</script>
</body>
Answer the question
In order to leave comments, you need to log in
Because it should be like this:
<body ng-app="app">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.1/angular.min.js"></script>
<script src="jquery-2.1.4.min.js"></script>
<div ng-controller="MainController"></div>
<script>
var app = angular.module('app', []);
app.service('$myService', function(){
return {hello: 'world'};
});
app.controller('MainController', ['$scope', '$myService', function($scope, $myService){
console.log($myService); // почему $myService undefined?
}]);
</script>
</body>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question