Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!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>
 
angular.module('Blog', [])
.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("https://jsonplaceholder.typicode.com/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() {
    
  });
  
}])
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
gmitticapro
0viewers