Created
October 4, 2017 13:05
-
-
Save gmittica/6cd4f41bbb39a43b4d1fdc67c83741ab to your computer and use it in GitHub Desktop.
Angular Lesson // source http://jsbin.com/pumojig
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<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> | |
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script> | |
<script src="http://unpkg.com/@uirouter/angularjs/release/angular-ui-router.min.js"></script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Angular Lesson</title> | |
<style id="jsbin-css"> | |
body > .container { | |
margin-top:20px; | |
} | |
</style> | |
</head> | |
<body ng-app="myApp"> | |
<div class="container" ng-controller="HomeCtrl" > | |
<div class="well"> | |
<h3>News list</h3> | |
</div> | |
<div news content="el" ng-repeat="el in news | limitTo : 5"></div> | |
</div> | |
<script id="jsbin-javascript"> | |
angular.module('Blog', []) | |
.constant("myConf", { | |
endpoint: "https://jsonplaceholder.typicode.com/" | |
}) | |
.config(['$httpProvider', 'myConf', function($httpProvider, myConf) { | |
$httpProvider.interceptors.push(function(){ | |
return { | |
request: function(config) { | |
// prepend base url | |
config.url = myConf.endpoint + config.url; | |
return config; | |
} | |
}; | |
}); | |
}]) | |
.directive("news", function() { | |
return { | |
restrict: 'A', | |
replace: true, | |
template: "<div>News: {{ content.title | transform : 'lower'}} </div>", | |
scope: { | |
content: "=" | |
} | |
}; | |
}) | |
.filter("transform", function() { | |
return function(input, pattern) { | |
if(pattern == 'upper') { | |
return input.toUpperCase(); | |
} | |
else if(pattern == 'lower') { | |
return input.toLowerCase(); | |
} | |
else { | |
return input; | |
} | |
} | |
}) | |
.factory("BlogService", ['$q', '$http', function($q, $http) { | |
var service = {}; | |
service.search = function() { | |
var d = $q.defer(); | |
$http.get("posts").then(function(response) { | |
d.resolve(response.data); | |
}); | |
return d.promise; | |
}; | |
return service; | |
}]) | |
; | |
angular.module("myApp", ["Blog"]) | |
.controller("HomeCtrl", ['$scope', 'BlogService', function($scope, BlogService) { | |
$scope.news = []; | |
BlogService.search().then(function(response) { | |
$scope.news = response; | |
}, function() { | |
}); | |
}]) | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<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> | |
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"><\/script> | |
<script src="//unpkg.com/@uirouter/angularjs/release/angular-ui-router.min.js"><\/script> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Angular Lesson</title> | |
</head> | |
<body ng-app="myApp"> | |
<div class="container" ng-controller="HomeCtrl" > | |
<div class="well"> | |
<h3>News list</h3> | |
</div> | |
<div news content="el" ng-repeat="el in news | limitTo : 5"></div> | |
</div> | |
</body> | |
</html> | |
</script> | |
<script id="jsbin-source-css" type="text/css">body > .container { | |
margin-top:20px; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">angular.module('Blog', []) | |
.constant("myConf", { | |
endpoint: "https://jsonplaceholder.typicode.com/" | |
}) | |
.config(['$httpProvider', 'myConf', function($httpProvider, myConf) { | |
$httpProvider.interceptors.push(function(){ | |
return { | |
request: function(config) { | |
// prepend base url | |
config.url = myConf.endpoint + config.url; | |
return config; | |
} | |
}; | |
}); | |
}]) | |
.directive("news", function() { | |
return { | |
restrict: 'A', | |
replace: true, | |
template: "<div>News: {{ content.title | transform : 'lower'}} </div>", | |
scope: { | |
content: "=" | |
} | |
}; | |
}) | |
.filter("transform", function() { | |
return function(input, pattern) { | |
if(pattern == 'upper') { | |
return input.toUpperCase(); | |
} | |
else if(pattern == 'lower') { | |
return input.toLowerCase(); | |
} | |
else { | |
return input; | |
} | |
} | |
}) | |
.factory("BlogService", ['$q', '$http', function($q, $http) { | |
var service = {}; | |
service.search = function() { | |
var d = $q.defer(); | |
$http.get("posts").then(function(response) { | |
d.resolve(response.data); | |
}); | |
return d.promise; | |
}; | |
return service; | |
}]) | |
; | |
angular.module("myApp", ["Blog"]) | |
.controller("HomeCtrl", ['$scope', 'BlogService', function($scope, BlogService) { | |
$scope.news = []; | |
BlogService.search().then(function(response) { | |
$scope.news = response; | |
}, function() { | |
}); | |
}])</script></body> | |
</html> | |
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
body > .container { | |
margin-top:20px; | |
} |
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
angular.module('Blog', []) | |
.constant("myConf", { | |
endpoint: "https://jsonplaceholder.typicode.com/" | |
}) | |
.config(['$httpProvider', 'myConf', function($httpProvider, myConf) { | |
$httpProvider.interceptors.push(function(){ | |
return { | |
request: function(config) { | |
// prepend base url | |
config.url = myConf.endpoint + config.url; | |
return config; | |
} | |
}; | |
}); | |
}]) | |
.directive("news", function() { | |
return { | |
restrict: 'A', | |
replace: true, | |
template: "<div>News: {{ content.title | transform : 'lower'}} </div>", | |
scope: { | |
content: "=" | |
} | |
}; | |
}) | |
.filter("transform", function() { | |
return function(input, pattern) { | |
if(pattern == 'upper') { | |
return input.toUpperCase(); | |
} | |
else if(pattern == 'lower') { | |
return input.toLowerCase(); | |
} | |
else { | |
return input; | |
} | |
} | |
}) | |
.factory("BlogService", ['$q', '$http', function($q, $http) { | |
var service = {}; | |
service.search = function() { | |
var d = $q.defer(); | |
$http.get("posts").then(function(response) { | |
d.resolve(response.data); | |
}); | |
return d.promise; | |
}; | |
return service; | |
}]) | |
; | |
angular.module("myApp", ["Blog"]) | |
.controller("HomeCtrl", ['$scope', 'BlogService', function($scope, BlogService) { | |
$scope.news = []; | |
BlogService.search().then(function(response) { | |
$scope.news = response; | |
}, function() { | |
}); | |
}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment