Skip to content
This repository has been archived by the owner on Aug 15, 2021. It is now read-only.

custom error message (help) #169

Open
ohnooo opened this issue Apr 9, 2017 · 0 comments
Open

custom error message (help) #169

ohnooo opened this issue Apr 9, 2017 · 0 comments

Comments

@ohnooo
Copy link

ohnooo commented Apr 9, 2017

First I want to thank you for this awesome module.... I having some trouble setting up custom error messages through defaultErrorMessageResolver.

I have gone through the documentation on creating customErrorMessageResolver but I was wondering if there is a simpler way.....

I am currently using Spring which already has i18 message resolver so I do not need set the culture.

Questions:
In the document, Error Message Resolver, is there a way to pass in data from a scope or a from a service??

errorMessages['myCustomError'] = 'My custom error message'; Instead of hardcoding a string would like to pass in a variable that is retrieved from the server.

So for example....

Resource

app.factory("Data" , function($resource){
	return $resource("http://localhost:8080/root/spa/data/:id", {id: "@id"}, {
		update:{
			method:'PUT'
		}
	});
});

Service that gets all the data needed for the page... something like this

angular.service("DataService", function(Data, $q){
   var self = {
       // ... some variables ...
       
       'messages' : null,
       loadPageData: function(){

           Data.get(function(data){				
		self.itemData = data.results;

		// Load Message Data
		self.messages = data.messages;  // data.messages is a key, value pare
	  });
       }
   }
});
angular.module('jcs-autoValidate')
    .run([
    'DataService',
    'defaultErrorMessageResolver',
    function (DataService, defaultErrorMessageResolver) {
        defaultErrorMessageResolver.getErrorMessages().then(function (errorMessages) {
          errorMessages['myCustomError'] = DataService.messages.myCustomError;
          errorMessages['anotherErrorMessage'] = DataService.messages.anotherErrorMessage;
        });
    }
]);
            

This does not work because angular.module('jcs-autoValidate').run runs before the DataService is ready. I have tried passing in $qPromise but still no luck... I still get an undefined on DataService.

app.run([
	'defaultErrorMessageResolver',
	'$q',
	'DataService',
	function (defaultErrorMessageResolver, $q, $scope, DataService) {
		console.log('run start');
		var d = $q.defer();

		defaultErrorMessageResolver.getErrorMessages().then(function (errorMessages, DataService) {
			console.log('inside defaultErrorMessageResolver');

			console.log(BookService);
			$scope.dataService = DataService;
			console.log('run',$scope.bookService);
			errorMessages['blankBookName'] = $scope.dataService.messages.NotBlank_book_name;

			d.resolve();

		});

		return d.promise;

	}
]);

Any insights is greatly appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant