My goal is to show a success message after clicking a button. Since I need this functionality in multiple controllers, I decided to implement it using a service. However, I am facing issues accessing the scope.
index.html
<div ng-controller="uploadController">
<div class="col-md-6" ng-click="uploadFile()" >
<div class="form-group has-success" id="divsubmitbtn">
<button type="submit" id="submit" class="btn btn-custom"
ng-click="submitData()" ng-disabled="isDisableSubmit">
<span class="glyphicon glyphicon-upload"></span> Upload</button>
</div>
</div>
<div class=" col-md-12">
<div ng-show="showError" ng-class="{fade:doFade}" class="alert alert-success">
<strong>Success:</strong> {{successMessage}}
</div>
</div>
</div>
controller.js
app.controller('uploadController', ['$scope','$timeout','$rootScope','displayMsgService',function($scope,$timeout,$rootScope,displayMsgService) {
$scope.uploadFile = function($scope,displayMsgService){
$scope.displayMsgService.show();
};
$rootScope.submitData = function() {
$scope.uploadFile();
};
}]);
service.js
app.factory('displayMsgService',function() {
return {
show : function($scope){
$scope.showError = false;
$scope.doFade = false;
$scope.showError = true;
$scope.successMessage = "success";
$timeout(function(){
$scope.doFade = true;
}, 2500);
}
}
});
I encountered the following error: Cannot read property 'displayMsgService' of undefined
Can someone point out what I might be missing?