Skip to content

Instantly share code, notes, and snippets.

@pfallasro
Created March 2, 2014 21:02
Show Gist options
  • Save pfallasro/9313860 to your computer and use it in GitHub Desktop.
Save pfallasro/9313860 to your computer and use it in GitHub Desktop.
AngularJS filter, service and function within a controller example
var myApp = angular.module('myApp', []);
//This is a service
myApp.Factory('Data', function () {
return {message:"I'm data from a service"}
})
//This is a filter
myApp.filter('reverse', function (Data) {
return function (text) {
return text.split("").reverse().join("") + Data.message;
}
})
//This is a controllers
function FirstCntrl ($scope, Data) {
$scope.data = Data;
}
//This is another controller
function SecondCntrl ($scope, Data) {
$scope.data = Data;
//This is a function in the controller, filter above does the same thing
$scope.reversedMessage = function (message) {
return message.split("").reverse().join("");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment