Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should we support $injector and $http #178

Open
hueitan opened this issue Dec 29, 2015 · 1 comment
Open

How should we support $injector and $http #178

hueitan opened this issue Dec 29, 2015 · 1 comment

Comments

@hueitan
Copy link
Owner

hueitan commented Dec 29, 2015

Situational

  1. ✓ Allow compilation for the output html in i18n case Able to compile validation output message? (template validation message) #96
  2. ✘ Support i18n - $translate.instant - angular-translate #176 AngularJS i18n support #177
  3. Able to use $http in the setExpression case / Backend Validation

✓ Compilation

Able to use filter and directive in the html

$validationProvider.setErrorHTML(function (msg) {
    return <span> {{ msg | translate }} </span>;
});
$validationProvider.setErrorHTML(function (msg) {
    return <custom-bar msg=msg />;
});

But this $compile will make the application more heavier.

Code given in this PR

✘ angular-translate

$validationProvider.setErrorHTML(function (msg) {
    return <span> this.$injector.get('$translate').instant(msg) </span>;
}

This is better and convenient stuff, use when you need it.

Not support $injector at this moment, use filter

$http/Backend Validation

Although we can easily setup setExpression and angular-validation support $q for the validation

But in the case doing backend validation, it's a plus if we can use $http inside the setExpression which used in config phase (we are not able to inject $http in config)

$validationProvider.setExpression({
    email: function (value) {
        var $http = $injector.get('$http');
        $http.get(url, value)
           .success()
           .error()
    });
});

Fix it

  1. Compilation for the output html - This is what angularjs way, should compile before every template
  2. adding $injector for the provider. - is this a good practice in angularjs?

Conlusion

We need to cover all the situations to provide more async/advanced validation.

@lvarayut
Copy link
Collaborator

lvarayut commented Jan 4, 2016

This is very good explanation and conclusion. Love it 👍

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

No branches or pull requests

2 participants