Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Translate directive and ngMessage not working #886

Closed
crisbeto opened this issue Jan 16, 2015 · 1 comment
Closed

Translate directive and ngMessage not working #886

crisbeto opened this issue Jan 16, 2015 · 1 comment

Comments

@crisbeto
Copy link

As mentioned in #702 the translate directive doesn't work when on the same element as https://docs.angularjs.org/api/ngMessages/directive/ngMessage.

Here's a simple example that breaks:

<form name="form">
    <input type="email" ng-model="email" ng-required="true" name="email" />

    <div ng-messages="form.email.$error">
        <div class="form-error" ng-message="required" translate="FIELD_REQUIRED"></div>
        <div class="form-error" ng-message="email" translate="EMAIL_INVALID"></div>
    </div>
</form>

I've been playing around with it a bit and it turns out that the error is caused because both the translate and ngMessage directive have the same priority(0). If we set the priority of translate lower, everything works as expected.
Here's a monkey patch that worked for me:

angular.module('pascalprecht.translate').config(['$provide', function($provide) {
    $provide.decorator('translateDirective', ['$delegate', function($delegate){
        var directive = $delegate[0];

        directive.priority--;

        return $delegate;

    }]);
}]);

Note that I'm not sure what consequences reducing the priority might have, but from what I'm seeing it works fine. I've also tested with interpolation and translate-values.

@crisbeto crisbeto changed the title Translate directive and ngMessage Translate directive and ngMessage not working Jan 16, 2015
knalli added a commit to knalli/angular-translate that referenced this issue Feb 8, 2015
@knalli
Copy link
Member

knalli commented Feb 8, 2015

I've added an additional option setter $translateProvider.directivePriority(0).

Defaults to 0 just like AJS default.

@knalli knalli closed this as completed Feb 8, 2015
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

2 participants