<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example10-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="angularExamples">
<div ng-controller="MainController">
<span ng-repeat="employee in employees">
<!-- Without Filter -->
<!-- {{employee.name}} - {{employee.id}} -->
<!--With Filter-->
{{employee.name | NameFilter}} - {{employee.id}}
<br/>
</span>
</div>
</body>
</html>
<!--
Copyright 2016 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->
(function(angular) {
'use strict';
var myApp = angular.module('angularExamples', []);
//Controller
myApp.controller('MainController', function($scope, MainService,MainServiceWithoutPromise, $q,EmployeeConstant) {
// $scope.employees = [{
// 'name': 'Shashi',
// 'id': 1340
// }, {
// 'name': 'Vinay',
// 'id': 1646
// }, {
// 'name': 'XYZ',
// 'id': 123
// }]
// (function init() {
// var defer = $q.defer();
// MainService.getEmployeeDetails().then(function(data) {
// $scope.employees = data;
// $scope.employees.push(EmployeeConstant);
// });
// return defer.promise;
// })();
(function initWithoutPromise() {
$scope.employees = MainServiceWithoutPromise.getEmployeeDetails();
})();
});
//Factory
myApp.factory('MainFactory', function($q, $http) {
return {
getEmployeeDetails: function() {
var request = $http.get('employees.json');
return request;
}
};
});
//Factory
myApp.factory('MainFactoryWithoutPromise', function() {
return {
getEmployeeDetails: function() {
return [{
'name': 'Shashi',
'id': 1340
}, {
'name': 'Vinay',
'id': 1646
}, {
'name': 'XYZ',
'id': 123
}];
}
};
});
//Service
myApp.service('MainService', function($q, MainFactory) {
this.getEmployeeDetails = function() {
var defer = $q.defer();
MainFactory.getEmployeeDetails().success(function(data) {
defer.resolve(data);
});
return defer.promise;
};
});
myApp.service('MainServiceWithoutPromise', function($q, MainFactory) {
this.getEmployeeDetails = function() {
return MainFactory.getEmployeeDetails();
};
});
//Filter
myApp.filter('NameFilter', function() {
return function(input) {
return input !== 'ABC' ? input : 'This is ABC';
};
});
//Constant
myApp.constant('EmployeeConstant', {'name':'constant','id':1111});
})(window.angular);
[{"name":"shashi","id":1340},{"name":"vinay","id":1646},{"name":"ABC","id":1233},{"name":"XYZ","id":2233}]
https://gist.github.com/demisx/9605099