Skip to content

Instantly share code, notes, and snippets.

@gmittica
Created October 13, 2017 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gmittica/b5290caa26d0825cb73365f0be801192 to your computer and use it in GitHub Desktop.
Save gmittica/b5290caa26d0825cb73365f0be801192 to your computer and use it in GitHub Desktop.
Lesson // source http://jsbin.com/valamahuzo
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script>
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<title>Lesson</title>
</head>
<body ng-app="myApp">
<div class="container" ng-controller="myCtrl">
<div class="well">
<h1>Services</h1>
</div>
</div>
<script id="jsbin-javascript">
angular.module("myApp", [])
.controller("myCtrl", ['$scope', 'myService', 'myOtherService', function($scope, myService, myOtherService) {
//myService.testMethod();
console.log(myOtherService.testMethod(5));
}])
.factory("myService", [function() {
return {
testMethod: function() {
console.log("i'm a service");
}
};
}])
.service("myOtherService", ['myService', function(myService) {
var service = {};
service.testMethod = function(number) {
myService.testMethod();
return service.otherMethod(number) * 2;
};
service.otherMethod = function(number) {
return number * 5;
}
return service;
}])
;
</script>
<script id="jsbin-source-javascript" type="text/javascript">angular.module("myApp", [])
.controller("myCtrl", ['$scope', 'myService', 'myOtherService', function($scope, myService, myOtherService) {
//myService.testMethod();
console.log(myOtherService.testMethod(5));
}])
.factory("myService", [function() {
return {
testMethod: function() {
console.log("i'm a service");
}
};
}])
.service("myOtherService", ['myService', function(myService) {
var service = {};
service.testMethod = function(number) {
myService.testMethod();
return service.otherMethod(number) * 2;
};
service.otherMethod = function(number) {
return number * 5;
}
return service;
}])
;</script></body>
</html>
angular.module("myApp", [])
.controller("myCtrl", ['$scope', 'myService', 'myOtherService', function($scope, myService, myOtherService) {
//myService.testMethod();
console.log(myOtherService.testMethod(5));
}])
.factory("myService", [function() {
return {
testMethod: function() {
console.log("i'm a service");
}
};
}])
.service("myOtherService", ['myService', function(myService) {
var service = {};
service.testMethod = function(number) {
myService.testMethod();
return service.otherMethod(number) * 2;
};
service.otherMethod = function(number) {
return number * 5;
}
return service;
}])
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment