question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatter support is not working

See original GitHub issue

Issue 1:

Use case: a date slider (data model is UNIX time in milliseconds)

<nouislider style="margin: 80px;"
                   (change)="change()"
                   [min]="1483228800000"
                   [max]="1485820800000"
                   [step]="3600000"
                   [(ngModel)]="model"
                   [format]="formatter"
                   [tooltips]="true"></nouislider>
model: number =  1484611200000;

formatter: NouiFormatter = {

  from(value: string): number {
    console.log('from', value);
    return Date.parse(value);
  },

  to(value: number): string {
    console.log('to', value);
    return new Date(value).toISOString();
  }

};

change(): void {
  console.log(this.model);
}

This example is not working.

Very odd: If you change model: number = 1484611200000 to model: string = '2017-01-17T00:00:00', then the slider seems to be working but the model will not be updated.

Issue 2:

<nouislider style="margin: 80px;"
                   (change)="change()"
                   [min]="0"
                   [max]="9"
                   [step]="3"
                   [(ngModel)]="model"
                   [format]="formatter"
                   [tooltips]="true"></nouislider>
model: number =  6;

formatter: NouiFormatter = {

  from(value: string): number {
    console.log('from', value);
    return Number(value);
  },

  to(value: number): string {
    console.log('to', value);
    return '#' + value;
  }

};

change(): void {
  console.log(this.model);
}

In this example the model will not be updated. The from() method is called once with a number value (the model value) and will be never called with a string value. The correct from() method should be:

from(value: string): number {
  console.log('from', value);
  return Number(value.slice(1,2));
}

but this is not working.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Martin-Luftcommented, Apr 23, 2018

@tb this works:

<nouislider style="width: 400px;"
                   [config]="config"
                   (change)="change()"
                   [(ngModel)]="model"></nouislider>
  model: number =  6;

  config: any = {
    range: {
      min: 0,
      max: 9
    },
    tooltips: {

      from(value: string): number {
        console.log('from', value);
        return Number(value.slice(1, 2));
      },

      to(value: number): string {
        console.log('to', value);
        return '#' + value;
      }

    },
    step: 3
  };

  change(): void {
    console.log(this.model);
  }
0reactions
Martin-Luftcommented, Apr 23, 2018

@nourhansaied I tested my code from above (https://github.com/tb/ng2-nouislider/issues/50#issuecomment-274765222) with Angular 5.2.10, ng2-nouislider 1.7.7, nouislider 11.1.0 and typescript 2.8.3 and it still works as expected…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Black does not support "Format Selection" command
In my situation (select black as the Python Formatting Provider in VS Code Settings), I encountered this warning everytime when I pasting ...
Read more >
formatter:off doesn't seem to be working
formatter:off doesn't seem to be working Follow. First, I definitely did enable: "Enable formatter markers in comments" option in "Settings | ...
Read more >
"Cannot play back the file. The format is not supported. (Error ...
Cause. This issue may occur for one or more of the following reasons: One or more Windows Media Player files are missing or...
Read more >
Common Problems with Formatter - Zapier Help
My Formatter step is not changing my dataAfter you've set up and tested your Formatter step, remember to map the output of the...
Read more >
Format on Save (prettier) stopped working with latest update
Same thing happened to me just now. I set prettier as the Default Formatter in Settings and it started working again. My Default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found