angular-pipe

How to use Numeral.js library in angular2/ionic 2 typescript app?

ぐ巨炮叔叔 提交于 2019-12-10 18:23:37
问题 I have been successful using Numeral.js library in my angularJs(1.x) applications to format my numbers in different formats. This is how I use angular1 filters: filter.js .filter('numeral', function () { return function (count) { var numericalFormat = numeral(count).format('0.0a'); return numericalFormat; }; }) For that I followed the official docs of Numeral.js and installed using npm. I also give reference to nodemodules in index.html. In the Browser <script src="node_modules/numeral

Pipe with piped parameter in angular 2

故事扮演 提交于 2019-12-10 18:11:43
问题 I'd like to write something like <p>{{"CURRENT_DATE" | translate:(value:(currentDate | date:getDateFormat))}}</p> where translate is a pipe function from ng2-translate. I'd like to display: "Today is 2016-07-13", so CURRENT_DATE is "Today is {{value}}" and expects a dynamic value. Depending on the user's locale, the current date format changes. I have a function getDateFormat which returns "yy-MM-dd" or "dd/MM/yy" . I know it is possible to chain pipes, but my case here is not really chaining

How do I make a pipe dynamic angular2

只愿长相守 提交于 2019-12-10 17:09:09
问题 I have the following UI buttons: [Show All] [Category 1] [Category 2] I would like to use filterBy from ngx-pipes (https://github.com/danrevah/ngx-pipes) to filter my data. Usage: array | filterBy: [prop, nested.prop, ...]: search: [strict | optional] From the docs, their example is: {{ users | filterBy: ['work.company']: 'Bar Tech' }} Instead of 'Bar Tech' being a 'hard coded' filter, I would like to assign a variable 'currentCategory' instead - how do I do that? Do I simply replace Bar Tech

How to use custom pipe on async pipe?

*爱你&永不变心* 提交于 2019-12-10 15:54:36
问题 I'm trying to create custom pipe on asynchronous pipe, I tried many solutions, but still not working. Here is the snippet of code. product.sort.ts - custom pipe import { PipeTransform, Pipe } from '@angular/core'; import { Observable } from 'rxjs/Observable'; @Pipe({ name: 'sortByName' }) export class ProductPipe implements PipeTransform{ /*transform(values: Array<any>, term:string){ return values.filter(obj => obj.pname.startsWith(term)) }*/ //CODE NOT WORKING >>>>> transform($value:

How to make *ngFor filter out duplicate month and year from date in angular 2?

▼魔方 西西 提交于 2019-12-08 10:11:50
问题 I have JSON array object which contains dates. I want to get displayed unique Month and Year(ignore day)from date. Please find my JSON object as below: { "records"[ { "id":"833599", "date":1507624517000, }, { "id":"828140", "date":1506346215000, }, { "id":"817349", "date":1504852602000, }, { "id":"817347", "date":1504851799000, }, { "id":"817346", "date":1504851689000, }, { "id":"811693", "date":1504086405000, }, { "id":"721986", "date":1501140629000, }, { "id":"673227", "date":1499435543000,

Angular 4: Store pipe output variable for use outside of template

廉价感情. 提交于 2019-12-08 05:00:56
问题 I am aware I can alias pipe output in angular 4 but this is only useful inside the template where it is aliased. Example <div *ngIf="race | async as raceModel"> <h2>{{ raceModel.name }}</h2> <small>{{ raceModel.date }}</small> </div> Here raceModel cannot be referenced outside of the ngIf. In my case, I am ordering and filtering a collection with pipes and want to get a hold of the length of the returned collection after filtering so I can update my NgbPagination. My code: <tr *ngFor="let

Angular 7 doesn't find pipes

 ̄綄美尐妖づ 提交于 2019-12-08 04:55:18
问题 I'm trying to build my Angular 7 project but every time I get an error saying ERROR in : Template parse errors: The pipe 'currency' could not be found.... But when I try to run the ng serve it does works as expected I've tried to build it with the --prod flag, and it doesn't work. If I remove the production flag, it build correctly. 回答1: Try this: in tsconfig.json change "angularCompilerOptions": { "enableIvy": true } for "angularCompilerOptions": { "enableIvy": false } 回答2: In order to use

Ngx-charts can't load bar charts directly with async pipe in angular

ε祈祈猫儿з 提交于 2019-12-07 17:37:25
My problem is similar to this stackoverflow post When I use async pipe to observe data from firebase and show it in chart, I can see the chart but prompt null error in console. Without async pipe, all errors are gone but I can't fetch data (duh it's async data). Help me please. Cause This is happening because the component cannot work with null values for results . Why? Async pipe is, as you say, used when you do not want to (or do not need to) subscribe in the component code, but do it in the template instead. Pipe, however, is a pure function: is has to return something each time it's called

invoke pipe when passing function as arg Pipe angular2

谁说我不能喝 提交于 2019-12-06 12:13:43
I have a list of emplyees and want to make a drop down with predefined department filter Im trying to make a filter pipe and pass a function as an arg it works only the first time its rendered but I want to invoke the pipe each time the user changes the selection Pipe: import { Pipe, PipeTransform, Injectable } from '@angular/core'; @Pipe({ name: 'filter' }) @Injectable() export class FilterPipe implements PipeTransform { transform(value: Array<any>, f) { return value.filter(x => f(x)); } } Component: constructor() { this.filterFunc = this.filterByDepatment.bind(this); } //filter function

Disable the default keyvalue pipe sort in angular

天大地大妈咪最大 提交于 2019-12-05 16:44:18
<tr *ngFor="let a of arrayOfObjects"> <td *ngFor="let item of cfValues | keyvalue"> {{item.value}} </td> </tr> I am just trying to print the items in the regular order but the key/value pipe does a default sorting based on the index. Is there a way to disable the default sorting? You need to return 0 if you want them to not be ordered. So in your cause you could either do <td *ngFor="let item of cfValues | keyvalue : 0"> But that would throw a ts error: TypeError: The comparison function must be either a function or undefined Else, you can create a function that returns 0 and use function