Hi Fernando, I'm actually using this already! The problem is that I have a string that's inside of a .config function that I need translated, but obviously can't use the $translate service because only providers can be used there.
So my random thought was what if I could do something extra hacky and wrap the strings in an object that is created by a new provider I made, which gets the $translate service set when it's instantiated, then I use the .valueOf function to call $translate() on it. Unfortunately it doesn't seem like it works too well. On Tuesday, April 5, 2016 at 6:27:17 PM UTC-4, Fernando Hernández Elías wrote: > > If you are doing this for translation I suggest: > > > https://angular-translate.github.io/docs/#/api/pascalprecht.translate.filter:translate > > {{'hello' | translate}} > > {{ myVar | translate}} > > <span translate="NAME"></span> > > https://angular-translate.github.io/ > > > > On Tuesday, April 5, 2016 at 5:06:17 PM UTC-5, Paul Selden wrote: >> >> Is there a way to control what gets output for a custom object in an >> angular expression? I was hoping that overriding the valueOf function would >> work, but unfortunately it displays it as an object: >> >> // js >> function SuperString(string) { >> this._string = string; >> } >> >> SuperString.prototype.valueOf = function() { >> return 'Super ' + this._string; >> }; >> >> var superString = new SuperString('String'); >> $scope.superString = superString; >> >> // html >> <div>{{ superString }}</div> >> >> // expected >> <div>Super String</div> >> >> // actual >> <div>{ "_string": "String"}</div> >> >> >> Any ideas about a way around this? My actual use case was for a wrapper >> around a string that automatically returns the translated value if one >> exists. >> > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
