Filter

Angular EggHead

by shriek

HTML

<div ng-app="myApp">
    <p ng-controller="FirstCtrl">{{ data.message|reverse }}</p>
</div>

JavaScript

//aka myApp service
var myApp = angular.module("myApp", []); //[] is dependcies
myApp.factory('Data', function () { //factory creates a service
    return {
        "message": "I'm data from a service"
    };
});

myApp.filter('reverse', function () {
    return function (text) {
        return text.split("").reverse().join("");
    }
});

function FirstCtrl($scope, Data) {
    $scope.data = Data;
}

function SecondCtrl($scope, Data) {
    $scope.data = Data;
}