You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+35-25Lines changed: 35 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -8,27 +8,26 @@ This is an Angular.js filter that applies [Numeral.js](http://numeraljs.com/) fo
8
8
9
9
2. Include either the minified or non-minified javascript file from the `/dist/` folder:
10
10
11
-
```html
11
+
```html
12
12
<scriptsrc="angular-numeraljs.js"></script>
13
-
```
13
+
```
14
14
15
15
3. Inject the `ngNumeraljs` filter into your app module:
16
16
17
-
```javascript
18
-
var myApp =angular.module('myApp', ['ngNumeraljs']);
19
-
```
20
-
21
-
4. Apply the filter:
17
+
```javascript
18
+
var myApp = angular.module('myApp', ['ngNumeraljs']);
19
+
```
22
20
23
-
```html
21
+
4. Apply the filter with the desired format string:
22
+
```html
24
23
<p>
25
24
{{ price | numeraljs:'$0,0.00' }}
26
25
</p>
27
-
```
26
+
```
28
27
29
28
## Advanced Usage
30
29
31
-
You can configure `ngNumberaljs` before actual usage with few options available.
30
+
You can configure `ngNumeraljs` during Angular's configuration phase using the $numeraljsConfigProvider:
32
31
33
32
```js
34
33
var app = angular.module('exampleApp', ['ngNumeraljs']);
@@ -38,9 +37,11 @@ app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
38
37
}]);
39
38
```
40
39
41
-
### Set formatters
40
+
Numeral.js must be already loaded in the browser prior to using `$numeraljsConfigProvider`.
42
41
43
-
`$numeraljsConfigProvider.setFormat(name, formatString)` - allows to define a named format, that can be used during formatting.
42
+
### Named Formats
43
+
44
+
`$numeraljsConfigProvider.setFormat(name, formatString)` - defines a named format which can be used in place of the format string in the filter.
44
45
45
46
```js
46
47
app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
@@ -51,14 +52,16 @@ app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
51
52
In markup,
52
53
53
54
```html
54
-
<p>
55
-
{{ price | numeraljs:'currency' }}
56
-
</p>
55
+
<p>
56
+
{{ price | numeraljs:'currency' }}
57
+
</p>
57
58
```
58
59
59
-
### Set default format
60
+
### Default Format
61
+
62
+
Numeral.js defines the default format as '0,0', so this format is used if none is provided to the filter.
60
63
61
-
`$numeraljsConfigProvider.setDefaultFormat(format)` - allows to define default format, one that is used if format is not specified.
64
+
`$numeraljsConfigProvider.setDefaultFormat(format)` - overrides the built-in default format.
62
65
63
66
```js
64
67
app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
@@ -69,14 +72,14 @@ app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
69
72
In markup,
70
73
71
74
```html
72
-
<p>
73
-
{{ price | numeraljs }} <!-- will produce 15.5 $ -->
74
-
</p>
75
+
<p>
76
+
{{ price | numeraljs }} <!-- will produce 15.5 $ -->
77
+
</p>
75
78
```
76
79
77
-
### Set language definition
80
+
### Custom Languages
78
81
79
-
`$numeraljsConfigProvider.setLanguage(langId, definition)` - allows to add language definition. Check out already available [languages](https://github.com/adamwdraper/Numeral-js/tree/master/languages).
82
+
`$numeraljsConfigProvider.setLanguage(langId, definition)` - adds new language definitions to Numeral.js. See the available list here: [languages](https://github.com/adamwdraper/Numeral-js/tree/master/languages).
80
83
81
84
```js
82
85
app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
@@ -103,9 +106,11 @@ app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
103
106
}]);
104
107
```
105
108
106
-
### Set current language
109
+
Languages can be loaded directly into Numeral.js as well, e.g. by loading the [language files](https://github.com/adamwdraper/Numeral-js/tree/master/languages) after Numeral.js is loaded. Angular-numeraljs can use these languages even if they are not set via this provider.
107
110
108
-
`$numeraljsConfigProvider.setCurrentLanguage(langId)` - allows to set currently used language.
111
+
### Select Language
112
+
113
+
`$numeraljsConfigProvider.setCurrentLanguage(langId)` - selects the current language. The language must be loaded either by `$numeraljsConfigProvider.setLanguage()` or by loading the Numeral.js language file.
109
114
110
115
```js
111
116
app.config(['$numeraljsConfigProvider', function ($numeraljsConfigProvider) {
@@ -137,4 +142,9 @@ This filter can be installed via Bower with the following dependency in the `bow
137
142
138
143
grunt build
139
144
140
-
The `/dist/' folder contains the regular and minified Javascript files.
145
+
The `/dist/` folder contains the regular and minified Javascript files.
146
+
147
+
4. Tests are automatically run during the build, but they can be run manually as well
0 commit comments