Skip to content

How should we support $injector and $http #178

Description

@hueitan

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.

Activity

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

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions