Created
March 2, 2014 21:02
-
-
Save pfallasro/9313860 to your computer and use it in GitHub Desktop.
AngularJS filter, service and function within a controller example
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
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