The requirement is to display a success message after click of a button.Since this has to be used across many controllers i decided to use a service to do the same. But i am not able to access 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 am getting the below error Cannot read property 'displayMsgService' of undefined
What is that i am missing out