formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

asynchronous angular-translate is not working with angular-formly #760

Open kalpitpandit opened 6 years ago

kalpitpandit commented 6 years ago

I load all my state level translation text via REST API asynchronously, Which is working totally fine when I use translation filter in HTML file but same is not working with angular-formly (when my API takes little time to give response).

Resolution : Angular-formly can put watch on label the way angular does and update translation text.

Here I am giving my code snippet to get clear idea

class LoginController {

constructor($translate){
    this.$translate = $translate;
    this.fields = this.getFields();
}

//  Return Login form fields
getFields(){
    return [
        {
            key: 'email',
            type: 'input',
            templateOptions: {
                label: this.$translate.instant('REGISTER_LABEL_EMAIL') **// This not getting translated once API response comes**
            },
            expressionProperties: {
                'templateOptions.label': '"REGISTER_LABEL_EMAIL" | translate' **// This not getting translated once API response comes**
            }
        }
}

}

{{'FORGOT_YOUR_PASSWORD_?' | translate}} **// This gets translates once API response comes**
{{'REMEMBER_ME' | translate}} **// This gets translates once API response comes**
{{'SIGN_IN' | translate}} **// This gets translates once API response comes**