Answer the question
In order to leave comments, you need to log in
How to understand given entry in Angular?
Good day to all. I installed a theme written in AngularJS as well.
A couple of questions arose during the analysis of the topic. Here is the original code for one of the controllers.
(function() {
'use strict';
angular.module('staff.controller', []).controller('StaffCtrl', [
'$scope', '$filter', function($scope, $filter) {
var init;
$scope.stores = [
{
name: 'Nijiya Market',
price: '$$',
sales: 292,
rating: 4.0
}, ... {
name: 'House of Bagels',
price: '$',
sales: 82,
rating: 4.4
}
];
$scope.searchKeywords = '';
$scope.filteredStores = [];
$scope.row = '';
$scope.select = function(page) {
var end, start;
start = (page - 1) * $scope.numPerPage;
end = start + $scope.numPerPage;
return $scope.currentPageStores = $scope.filteredStores.slice(start, end);
};
$scope.onFilterChange = function() {
$scope.select(1);
$scope.currentPage = 1;
return $scope.row = '';
};
$scope.onNumPerPageChange = function() {
$scope.select(1);
return $scope.currentPage = 1;
};
$scope.onOrderChange = function() {
$scope.select(1);
return $scope.currentPage = 1;
};
$scope.search = function() {
$scope.filteredStores = $filter('filter')($scope.stores, $scope.searchKeywords);
return $scope.onFilterChange();
};
$scope.order = function(rowName) {
if ($scope.row === rowName) {
return;
}
$scope.row = rowName;
$scope.filteredStores = $filter('orderBy')($scope.stores, rowName);
return $scope.onOrderChange();
};
$scope.numPerPageOpt = [3, 5, 10, 20];
$scope.numPerPage = $scope.numPerPageOpt[2];
$scope.currentPage = 1;
$scope.currentPageStores = [];
init = function() {
$scope.search();
return $scope.select($scope.currentPage);
};
return init();
}
]);
}).call(this);
Answer the question
In order to leave comments, you need to log in
Shit code and all. Don't sweat it. The author of this code wrote too much in jQuery.
I have been working with Angular for several years, but I am just as intrigued by the motivation of the author of this code.
However, there is one guess. He seems to really like it when functions return a value (note, EVERY function returns something, even if it is not necessary at all), so it makes sense that both init and the controller function itself should return something.
In general, the organization of the code in this controller leaves much to be desired.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question