Angular material displayWith isn't working with ngx-translate2019 Community Moderator ElectionWhy don't self-closing script tags work?How do JavaScript closures work?How does JavaScript .prototype work?How does the “this” keyword work?How does data binding work in AngularJS?What is the difference between angular-route and angular-ui-router?@Directive v/s @Component in AngularAngular/RxJs When should I unsubscribe from `Subscription`Huge number of files generated for every Angular projectCan't bind to 'ngModel' since it isn't a known property of 'input'
Is it true that real estate prices mainly go up?
What is the blue range indicating on this manifold pressure gauge?
Am I not good enough for you?
How could a female member of a species produce eggs unto death?
How to make readers know that my work has used a hidden constraint?
US to Europe trip with Montreal layover - is 52 minutes enough?
Why must traveling waves have the same amplitude to form a standing wave?
Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?
Why do Australian milk farmers need to protest supermarkets' milk price?
Should we release the security issues we found in our product as CVE or we can just update those on weekly release notes?
Ban on all campaign finance?
What is the difference between "shut" and "close"?
Potentiometer like component
If Invisibility ends because the original caster casts a non-concentration spell, does Invisibility also end on other targets of the original casting?
When two POV characters meet
Make a transparent 448*448 image
Is it ok to include an epilogue dedicated to colleagues who passed away in the end of the manuscript?
Excess Zinc in garden soil
Is it illegal in Germany to take sick leave if you caused your own illness with food?
Rejected in 4th interview round citing insufficient years of experience
The three point beverage
How can I discourage/prevent PCs from using door choke-points?
When were linguistics departments first established
Playing ONE triplet (not three)
Angular material displayWith isn't working with ngx-translate
2019 Community Moderator ElectionWhy don't self-closing script tags work?How do JavaScript closures work?How does JavaScript .prototype work?How does the “this” keyword work?How does data binding work in AngularJS?What is the difference between angular-route and angular-ui-router?@Directive v/s @Component in AngularAngular/RxJs When should I unsubscribe from `Subscription`Huge number of files generated for every Angular projectCan't bind to 'ngModel' since it isn't a known property of 'input'
I am using [displayWith] directive in my mat-autocomplete. It works fine when i am manually selecting values but when i reload the page i am not getting translation. Parameter necessary for translation is asynchronously loaded from query params in ngOnInit. So I rely on async parameter but my displayFunction() is sync function. How to resolve that?
Without [displayWith] function everything is working OK but without translation (it's just displaying pure values what i do not want). So i am sure that rest of the code is proper.
My mat-autocomplete:
<mat-form-field [formGroup]="cityForm"
appearance="outline"
floatLabel="never"
color="primary">
<mat-icon matPrefix>location_on</mat-icon>
<input type="text" placeholder=" translate "
aria-label="Number" matInput
formControlName="cityControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="onSelectionChanged($event.option.value)"
[displayWith]="displayFn.bind(this)">
<mat-option>
translate
</mat-option>
<mat-option *ngFor="let city of filtredCities | async" [value]="city">
translate:" city: '" + city +"' "
</mat-option>
</mat-autocomplete>
</mat-form-field>
My displayWith function is below:
displayFn(val: string){
if (!val) return '';
let stringToReturn;
this.translate.get('job_offer_search_bar.job-offer-search-bar-city-form.city', city: val).subscribe(value =>
console.log('inside subscribe', value);
stringToReturn = value;
);
console.log('after sub', stringToReturn);
if (stringToReturn != undefined)
return stringToReturn;
else
return 'Sorry, value has not been translated';
Console.log in subscribe
is invoked after console.log after subscribe
. So subscribe is made after i get my parameter for translation, so after my return...
I need some trick or tip to pass my translated string as a return.
I assume that there is a way to do that. Any help will be appreaciated.
javascript angular typescript rxjs ngx-translate
add a comment |
I am using [displayWith] directive in my mat-autocomplete. It works fine when i am manually selecting values but when i reload the page i am not getting translation. Parameter necessary for translation is asynchronously loaded from query params in ngOnInit. So I rely on async parameter but my displayFunction() is sync function. How to resolve that?
Without [displayWith] function everything is working OK but without translation (it's just displaying pure values what i do not want). So i am sure that rest of the code is proper.
My mat-autocomplete:
<mat-form-field [formGroup]="cityForm"
appearance="outline"
floatLabel="never"
color="primary">
<mat-icon matPrefix>location_on</mat-icon>
<input type="text" placeholder=" translate "
aria-label="Number" matInput
formControlName="cityControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="onSelectionChanged($event.option.value)"
[displayWith]="displayFn.bind(this)">
<mat-option>
translate
</mat-option>
<mat-option *ngFor="let city of filtredCities | async" [value]="city">
translate:" city: '" + city +"' "
</mat-option>
</mat-autocomplete>
</mat-form-field>
My displayWith function is below:
displayFn(val: string){
if (!val) return '';
let stringToReturn;
this.translate.get('job_offer_search_bar.job-offer-search-bar-city-form.city', city: val).subscribe(value =>
console.log('inside subscribe', value);
stringToReturn = value;
);
console.log('after sub', stringToReturn);
if (stringToReturn != undefined)
return stringToReturn;
else
return 'Sorry, value has not been translated';
Console.log in subscribe
is invoked after console.log after subscribe
. So subscribe is made after i get my parameter for translation, so after my return...
I need some trick or tip to pass my translated string as a return.
I assume that there is a way to do that. Any help will be appreaciated.
javascript angular typescript rxjs ngx-translate
add a comment |
I am using [displayWith] directive in my mat-autocomplete. It works fine when i am manually selecting values but when i reload the page i am not getting translation. Parameter necessary for translation is asynchronously loaded from query params in ngOnInit. So I rely on async parameter but my displayFunction() is sync function. How to resolve that?
Without [displayWith] function everything is working OK but without translation (it's just displaying pure values what i do not want). So i am sure that rest of the code is proper.
My mat-autocomplete:
<mat-form-field [formGroup]="cityForm"
appearance="outline"
floatLabel="never"
color="primary">
<mat-icon matPrefix>location_on</mat-icon>
<input type="text" placeholder=" translate "
aria-label="Number" matInput
formControlName="cityControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="onSelectionChanged($event.option.value)"
[displayWith]="displayFn.bind(this)">
<mat-option>
translate
</mat-option>
<mat-option *ngFor="let city of filtredCities | async" [value]="city">
translate:" city: '" + city +"' "
</mat-option>
</mat-autocomplete>
</mat-form-field>
My displayWith function is below:
displayFn(val: string){
if (!val) return '';
let stringToReturn;
this.translate.get('job_offer_search_bar.job-offer-search-bar-city-form.city', city: val).subscribe(value =>
console.log('inside subscribe', value);
stringToReturn = value;
);
console.log('after sub', stringToReturn);
if (stringToReturn != undefined)
return stringToReturn;
else
return 'Sorry, value has not been translated';
Console.log in subscribe
is invoked after console.log after subscribe
. So subscribe is made after i get my parameter for translation, so after my return...
I need some trick or tip to pass my translated string as a return.
I assume that there is a way to do that. Any help will be appreaciated.
javascript angular typescript rxjs ngx-translate
I am using [displayWith] directive in my mat-autocomplete. It works fine when i am manually selecting values but when i reload the page i am not getting translation. Parameter necessary for translation is asynchronously loaded from query params in ngOnInit. So I rely on async parameter but my displayFunction() is sync function. How to resolve that?
Without [displayWith] function everything is working OK but without translation (it's just displaying pure values what i do not want). So i am sure that rest of the code is proper.
My mat-autocomplete:
<mat-form-field [formGroup]="cityForm"
appearance="outline"
floatLabel="never"
color="primary">
<mat-icon matPrefix>location_on</mat-icon>
<input type="text" placeholder=" translate "
aria-label="Number" matInput
formControlName="cityControl" [matAutocomplete]="auto">
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="onSelectionChanged($event.option.value)"
[displayWith]="displayFn.bind(this)">
<mat-option>
translate
</mat-option>
<mat-option *ngFor="let city of filtredCities | async" [value]="city">
translate:" city: '" + city +"' "
</mat-option>
</mat-autocomplete>
</mat-form-field>
My displayWith function is below:
displayFn(val: string){
if (!val) return '';
let stringToReturn;
this.translate.get('job_offer_search_bar.job-offer-search-bar-city-form.city', city: val).subscribe(value =>
console.log('inside subscribe', value);
stringToReturn = value;
);
console.log('after sub', stringToReturn);
if (stringToReturn != undefined)
return stringToReturn;
else
return 'Sorry, value has not been translated';
Console.log in subscribe
is invoked after console.log after subscribe
. So subscribe is made after i get my parameter for translation, so after my return...
I need some trick or tip to pass my translated string as a return.
I assume that there is a way to do that. Any help will be appreaciated.
javascript angular typescript rxjs ngx-translate
javascript angular typescript rxjs ngx-translate
asked Mar 7 at 10:49
ShaibyShaiby
364
364
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Observables are, at the most cases, async functions.
Depending on your implementation you may use translate.instant
displayFn(val: string) defaultMessage
: '';
If the instant function is called before the translation file is loaded, it will return undefined.
EDIT:
displayFn(val: string) 'Sorry, value has not been translated')
)
return val
? translate$
: of('');
[displayWith]="displayFn.bind(this) | async"
I usedtranslate.instant
but as i said i need parameter for translation which is loaded async :( Sotranslate.instant
was giving me just translation id... In this casejob_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
1
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
|
show 1 more comment
Solution of the problem was tricky. I had to use *ngIf on mat-form-field to wait for my translated label:
<mat-form-field *ngIf="isReady$ | async" [formGroup]="cityForm"
Condition should be fulfilled when translation is done so I had to do this in ngOnInit:
this.isReady$ = this.translate.get('translate_id').pipe(mapTo(true));
So now element is not beeing displayed before translation is returned from translate service. It's a workaround but I haven't found other solution.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55041996%2fangular-material-displaywith-isnt-working-with-ngx-translate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Observables are, at the most cases, async functions.
Depending on your implementation you may use translate.instant
displayFn(val: string) defaultMessage
: '';
If the instant function is called before the translation file is loaded, it will return undefined.
EDIT:
displayFn(val: string) 'Sorry, value has not been translated')
)
return val
? translate$
: of('');
[displayWith]="displayFn.bind(this) | async"
I usedtranslate.instant
but as i said i need parameter for translation which is loaded async :( Sotranslate.instant
was giving me just translation id... In this casejob_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
1
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
|
show 1 more comment
Observables are, at the most cases, async functions.
Depending on your implementation you may use translate.instant
displayFn(val: string) defaultMessage
: '';
If the instant function is called before the translation file is loaded, it will return undefined.
EDIT:
displayFn(val: string) 'Sorry, value has not been translated')
)
return val
? translate$
: of('');
[displayWith]="displayFn.bind(this) | async"
I usedtranslate.instant
but as i said i need parameter for translation which is loaded async :( Sotranslate.instant
was giving me just translation id... In this casejob_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
1
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
|
show 1 more comment
Observables are, at the most cases, async functions.
Depending on your implementation you may use translate.instant
displayFn(val: string) defaultMessage
: '';
If the instant function is called before the translation file is loaded, it will return undefined.
EDIT:
displayFn(val: string) 'Sorry, value has not been translated')
)
return val
? translate$
: of('');
[displayWith]="displayFn.bind(this) | async"
Observables are, at the most cases, async functions.
Depending on your implementation you may use translate.instant
displayFn(val: string) defaultMessage
: '';
If the instant function is called before the translation file is loaded, it will return undefined.
EDIT:
displayFn(val: string) 'Sorry, value has not been translated')
)
return val
? translate$
: of('');
[displayWith]="displayFn.bind(this) | async"
edited Mar 7 at 11:17
answered Mar 7 at 10:58
Leandro LimaLeandro Lima
80129
80129
I usedtranslate.instant
but as i said i need parameter for translation which is loaded async :( Sotranslate.instant
was giving me just translation id... In this casejob_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
1
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
|
show 1 more comment
I usedtranslate.instant
but as i said i need parameter for translation which is loaded async :( Sotranslate.instant
was giving me just translation id... In this casejob_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
1
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
I used
translate.instant
but as i said i need parameter for translation which is loaded async :( So translate.instant
was giving me just translation id... In this case job_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
I used
translate.instant
but as i said i need parameter for translation which is loaded async :( So translate.instant
was giving me just translation id... In this case job_offer_search_bar.job-offer-search-bar-city-form.city
– Shaiby
Mar 7 at 11:04
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
And ur solution is returning me an empty string ' '
– Shaiby
Mar 7 at 11:12
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Try this new code I posted. Keep in mind it is not good to use the pipe async with functions neither to bind functions to properties at all.
– Leandro Lima
Mar 7 at 11:20
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
Unfortunately now i am getting 2 errors in console now: Error: InvalidPipeArgument: 'function () [native code] ' for pipe 'AsyncPipe' and TypeError: Cannot read property 'dispose' of null. But everything compiles fine
– Shaiby
Mar 7 at 11:35
1
1
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
I see, I'm sorry I running out of ideas =/
– Leandro Lima
Mar 7 at 11:50
|
show 1 more comment
Solution of the problem was tricky. I had to use *ngIf on mat-form-field to wait for my translated label:
<mat-form-field *ngIf="isReady$ | async" [formGroup]="cityForm"
Condition should be fulfilled when translation is done so I had to do this in ngOnInit:
this.isReady$ = this.translate.get('translate_id').pipe(mapTo(true));
So now element is not beeing displayed before translation is returned from translate service. It's a workaround but I haven't found other solution.
add a comment |
Solution of the problem was tricky. I had to use *ngIf on mat-form-field to wait for my translated label:
<mat-form-field *ngIf="isReady$ | async" [formGroup]="cityForm"
Condition should be fulfilled when translation is done so I had to do this in ngOnInit:
this.isReady$ = this.translate.get('translate_id').pipe(mapTo(true));
So now element is not beeing displayed before translation is returned from translate service. It's a workaround but I haven't found other solution.
add a comment |
Solution of the problem was tricky. I had to use *ngIf on mat-form-field to wait for my translated label:
<mat-form-field *ngIf="isReady$ | async" [formGroup]="cityForm"
Condition should be fulfilled when translation is done so I had to do this in ngOnInit:
this.isReady$ = this.translate.get('translate_id').pipe(mapTo(true));
So now element is not beeing displayed before translation is returned from translate service. It's a workaround but I haven't found other solution.
Solution of the problem was tricky. I had to use *ngIf on mat-form-field to wait for my translated label:
<mat-form-field *ngIf="isReady$ | async" [formGroup]="cityForm"
Condition should be fulfilled when translation is done so I had to do this in ngOnInit:
this.isReady$ = this.translate.get('translate_id').pipe(mapTo(true));
So now element is not beeing displayed before translation is returned from translate service. It's a workaround but I haven't found other solution.
answered Mar 8 at 9:28
ShaibyShaiby
364
364
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55041996%2fangular-material-displaywith-isnt-working-with-ngx-translate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown