(function(){ 'use strict'; angular.module('shared') .component('profilePhotoUpload', { templateUrl: '/shared/js/angular/profile-photo-upload/profile-photo-upload.html', controller: 'profilePhotoUploadController', bindings: { hasProfilePhoto: '<', profilePic: '@', upload: '<', close: '<' }, }) .controller('profilePhotoUploadController', ['photoUploadService', '$scope', 'messageHandler', function profilePhotoUploadController (photoUploadService, $scope, messageHandler){ var ctrl = this; ctrl.$onInit = function(){ if(ctrl.hasProfilePhoto){ ctrl.photo = ctrl.profilePic; } else{ ctrl.photo = '/shared/images/default-profile.png'; } } ctrl.startUpload = function(){ var file = $scope.newpic; photoUploadService.uploadProfilePic(file).then(function(data){ ctrl.upload(data); }).catch(function(error){ console.log(error); messageHandler.publishError(error.data.message); }); } }]); })();