Reputation: 27
Here is my code
/// <reference path="angular.min.js" />
var myApp = angular.module("myModule", []).controller("myController", function($scope) {
var employees = [{
name: "Ben",
dateOfBirth: new Date("November 23,1980"),
gender: "Male",
salary: 55000.788
}, {
name: "Sara",
dateOfBirth: new Date("May 05,1970"),
gender: "Female",
salary: 68000
}, {
name: "Mark",
dateOfBirth: new Date("August 15,1974"),
gender: "Male",
salary: 57000
}, {
name: "Pam",
dateOfBirth: new Date("October 27,1979"),
gender: "Female",
salary: 53000
}, {
name: "Todd",
dateOfBirth: new Date("December 30,1983"),
gender: "Male",
salary: 60000
}];
$scope.employees = employees;
$scope.sortColumn = "name";
$scope.reverseSort = false;
$scope.sortData = function(column) {
$scope.reverseSort = ($scope.sortColumn == column) ? !$scope.reverseSort : false;
$scope.sortColumn = column;
}
$scope.getSortClass = function(column) {
if ($scope.sortColumn == column)
return $scope.reverseSort ? 'arrow-down' : 'arrow-up';
return '';
}
});
I just want to ask that are employees,sortColumn and reverse sort are separate models or they belong to one model and what are the sortData and getSortClass in this files are they behavior in our model please explain...Thanks in advance.
Upvotes: 0
Views: 51
Reputation: 1883
Where to start... The variables in your codeblock all belong to the myController
controller you have defined. They are instantiated when the controller is invoked through the $scope
dependency, as well as any injected dependencies there may be.
sortData
and getSortClass
are functions declared in the scope of your controller. You cannot access them from another controller unless you traverse angulars $rootScope
or using a listener. As for what those functions do, @kapil yadav has given an explanation.
Upvotes: 0
Reputation: 706
SortData, contains the column name from which you want to sort and the reverseSort is a property of current employee object, which is set to true once the sort order is descending ( binary 0 ).
getSortClass fetch the current sort order in binary format ( 0 or 1) and update the reverseSort property accordingly.
Upvotes: 1