header.controller.js 997 B

123456789101112131415161718192021222324252627
  1. (function ()
  2. {
  3. 'use strict';
  4. app.controller('Header', [ '$scope','$translate', 'books.repository', '$rootScope','$location',function ($scope, $translate, booksRepository, $rootScope, $location){
  5. $scope.isLogged = function() {
  6. return localStorage.getItem('authToken') ? true : false;
  7. };
  8. $scope.langSwitch = function(){
  9. var lang = localStorage.getItem('preferredLanguage');
  10. var curentleng = lang === 'en'? 'ru' : 'en';
  11. $translate.use(curentleng);
  12. localStorage.setItem('preferredLanguage', curentleng);
  13. };
  14. $scope.search = function() {
  15. booksRepository.searchBy($scope.searchString)
  16. .then(function(response){
  17. sessionStorage.setItem('searchResult', JSON.stringify(response.data))
  18. $rootScope.$broadcast('search', response.data);
  19. $location.path('/books')
  20. })
  21. }
  22. }
  23. ]);
  24. }
  25. )();