generator-angular-fullstack icon indicating copy to clipboard operation
generator-angular-fullstack copied to clipboard

Getting error using auth service in angular [email protected]

Open akshayseth opened this issue 8 years ago • 0 comments

Hello, I am using Auth.getCurrentUser but in browser it is giving me an error which is below: angular.js:13236 TypeError: Cannot read property 'getCurrentUser' of undefined at new AdvertisementComponent (advertisement.controller.js:7) at Object.invoke (angular.js:4604) at extend.instance (angular.js:9855) at nodeLinkFn (angular.js:8927) at angular.js:9231 at processQueue (angular.js:15552) at angular.js:15568 at Scope.$eval (angular.js:16820) at Scope.$digest (angular.js:16636) at Scope.$apply (angular.js:16928)

Below is my code: 'use strict';

(function () {

class AdvertisementComponent { constructor($scope, Upload, $http, $timeout, Auth) { var userDetails = Auth.getCurrentUser; $scope.uploadPic = function (file) { $scope.advert.userDetails = { "name": userDetails.name, "email": userDetails.email, "role": userDetails.role } console.log($scope.advert) file.upload = Upload.upload({ url: '/api/uploaders/uploads', method: 'POST', fields: { details: $scope.advert }, file: file, fileFormDataName: 'photo' });

    file.upload.then(function (response) {
      console.log("Postcontroller: upload then ");
      $timeout(function () {
        file.result = response.data;
      });
    }, function (response) {
      if (response.status > 0)
        $scope.errorMsg = response.status + ': ' + response.data;
    });

    file.upload.progress(function (evt) {
      // Math.min is to fix IE which reports 200% sometimes
      file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
      console.log("PostController: upload progress " + file.progress);
    });
    file.upload.success(function (data, status, headers, config) {
      // file is uploaded successfully
      console.log('file ' + config.file.name + 'is uploaded successfully. Response: ' + data);
      console.log(data);
    });
  }
}

}

angular.module('ctrlCApp') .component('advertisement', { templateUrl: 'app/advertisement/advertisement.html', controller: 'AdvertisementComponent' }) .controller('AdvertisementComponent', AdvertisementComponent); AdvertisementComponent.$inject=['Upload','Auth']; })();

akshayseth avatar Jul 10 '17 10:07 akshayseth