标签: angular-pipe

Angular:limitTo管道无法正常工作

我试图limitTo在字符串上运行Angular2上的管道:

{{ item.description | limitTo : 20 }} 
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

The pipe 'limitTo' could not be found
Run Code Online (Sandbox Code Playgroud)

是否有可能在Angular2中移除此管道?

这是我的 app.module

从'./limit-to.pipe'导入{TruncatePipe};

@NgModule({
  imports: [ 
    BrowserModule,
    FormsModule,
    HttpModule,
    InMemoryWebApiModule.forRoot(InMemoryDataService),
    RouterModule.forRoot([
      {
        path: '',
        redirectTo: '/home',
        pathMatch: 'full'
      },
      {
        path: 'home',
        component: GridComponent
      },
    ])
  ],
  declarations: [ 
    AppComponent, 
    TopNavComponent, 
    GridComponent,
    TruncatePipe
  ],
  providers: [
    PinService,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

我使用管道的网格组件:

import { Component,OnInit } from '@angular/core';
import { Router }   from '@angular/router'; …
Run Code Online (Sandbox Code Playgroud)

angular-pipe angular

19
推荐指数
3
解决办法
3万
查看次数

Angular 2.0版本:管道和指令不再是@Component的属性

我刚刚将我在RC5上构建的应用程序升级到最终版本,而且我对我现在应该声明指令和管道的方式感到困惑.我收到这个错误:

ERROR在[默认] C:\ xampp\htdocs\meriem-car\public\src\app\components\administration.component.ts:12:4类型'{moduleId:string; selector:string; 指令:typeof LoginComponent []; templateUrl:string; }'不能分配给'Component'类型的参数.对象文字只能指定已知属性,"组件"类型中不存在"指令".

angular-directive angular-pipe angular

18
推荐指数
1
解决办法
1万
查看次数

angular keyvalue pipe排序属性/按顺序迭代

使用Angular keyvalue管道迭代对象的属性时,如下所示:

<div *ngFor="let item of object | keyvalue">
  {{item.key}}:{{item.value}}
</div>
Run Code Online (Sandbox Code Playgroud)

我遇到了一个问题,即属性没有按预期的顺序迭代.这条评论表明我并不是唯一一个遇到这个问题的人:

如何在Angular中使用ngFor循环对象属性

有人可以建议在使用keyvalue管道时决定迭代顺序的内容以及如何强制执行特定的迭代顺序吗?我理想的迭代顺序是添加属性的顺序.

谢谢

angular-pipe angular

17
推荐指数
7
解决办法
1万
查看次数

指定的值无法解析,或者使用数字管道时超出范围

无法解析指定值或超出范围

当我得到我的对象时,我用管道格式化一个数字,但它返回此警告并且不显示该值。如果我删除它,它就会显示。

这不显示该值

  <input name="value" [ngModel]="value | number : '1.2-2'"/>
Run Code Online (Sandbox Code Playgroud)

这将显示该值

  <input name="value" [ngModel]="value"/>
Run Code Online (Sandbox Code Playgroud)

TS 这里我在列表中选择对象后通过它的 id 获取它。

  ngOnInit(){
    this.get();
  }

get() {
    this.service.get(this.id).subscribe(
      (data) => {
        this.object = data;
        this.name = this.object.name;
        this.value = this.object.value;
      },
      (error) => {
        console.log(error);
      }
    );
  }
Run Code Online (Sandbox Code Playgroud)

该值是一个数字,我在控制台中得到它没有任何问题。

angular-pipe angular

17
推荐指数
1
解决办法
7万
查看次数

Angular2在自定义管道中使用基本管道

我想为基本的angular2管道添加一些额外的功能.

即.在货币管道上完成了一些额外的格式化.为此,我想在自定义管道的组件代码中使用现有管道.

有什么办法可以做到吗?

@Pipe({name: 'formatCurrency'})
export class FormatCurrency implements PipeTransform {
  transform(value:number, args:string[]) : any {
    var formatted = value/100;

    //I would like to use the basic currecy pipe here.
    ///100 | currency:'EUR':true:'.2'

    return 'Do some extra things here ' + formatted;
  }
}
Run Code Online (Sandbox Code Playgroud)

angular-pipe angular

15
推荐指数
2
解决办法
7096
查看次数

多个模块中的管道重用,NG6007(由多个 NgModule 声明)或 NG6002(无法解析为 NgModule 类),

我的管道位于apps\administrator\src\app\modules\messenger\pipes\custom-message.pipe.ts

import { Pipe, PipeTransform } from '@angular/core';

/**
 * Pipe for Custom Message for boolean
 */
@Pipe({
  name: 'customMessage',
})
export class CustomMessagePipe implements PipeTransform {
  public transform(value: boolean, trueString: string, falseString: string): string {
    //The code
  }
}
Run Code Online (Sandbox Code Playgroud)

在主模块apps\administrator\src\app\app.module.ts文件中:

import { CustomMessagePipe } from './modules/messenger/pipes/custom-message.pipe';
...
@NgModule({
  declarations: [..., CustomMessagePipe],
  providers: [...],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)

现在,我有两个FormSmsModule模块FormSmtpModule

FormSmsModule位于apps\administrator\src\app\modules\messenger\form-sms

FormSmtpModule位于apps\administrator\src\app\modules\messenger\form-smtp

按照这个答案/sf/answers/4372816381/

在数组上使用的文件apps\administrator\src\app\modules\messenger\form-sms\form-sms.module.ts中,我有:CustomMessagePipeimports

import …
Run Code Online (Sandbox Code Playgroud)

module typescript angular-pipe angular

14
推荐指数
1
解决办法
1万
查看次数

在Angular 2中搜索对象的所有属性中的字符串

如何使用TS在Angular 2中搜索对象的所有属性中的字符串.

如果用户键入一个值,我想搜索所有属性值以推送符合键入值的客户,我会在带有搜索框的表中呈现一组客户.

export var CUSTOMER: Client[] = [
  { id: 1, name: 'John', phone: '888-888-888'},
  { id: 2, name: 'Nick', phone: '555-888-888'},
  { id: 3, name: 'Mike', phone: '666-888-888'},
];
Run Code Online (Sandbox Code Playgroud)

过滤管

import {Pipe, PipeTransform, Injectable} from "@angular/core";

@Pipe({
  name: 'filter',
  pure: false
})
@Injectable()
export class Ng2SearchPipe implements PipeTransform {

  transform(items: any, term: any): any {
    if (term === undefined) {
      return items;
    }

    return items.filter(function(item){
      return item.name.toLowerCase().includes(term.toLowerCase());
    });
  }
}
Run Code Online (Sandbox Code Playgroud)

在上面的过滤管道中,我只能按名称搜索.我不知道如何处理这个问题.我应该为Customer对象创建一个方法,该方法返回连接的所有属性值,然后在此连接值上搜索该术语吗?

angular-pipe angular2-filtering angular

10
推荐指数
2
解决办法
9354
查看次数

手动触发管道更新

我创建了一个能够*ngFor与对象一起使用的管道.但是,更新对象时,管道不会更新.我已经找到了解决办法在这里通过使用状态的管道pure: false.

对于我的用例,这个解决方案在性能方面是不可接受的,因为它会为每次更改刷新管道(我几乎到处都使用这个管道来渲染复杂的元素).

有没有办法触发管道的手动刷新,所以它只在我想要时刷新?

这是一个plunker - 要查看问题,请尝试通过单击-按钮删除名称.如果添加,pure:false您将看到它将起作用:

@Pipe({name: 'keys', pure: false})
export class Keys implements PipeTransform {
  transform(value, args:string[]) : any {
    let keys = [];
    for (let key in value) {
      keys.push({key: key, value: value[key]});
    }
    return keys;
  }
}
Run Code Online (Sandbox Code Playgroud)

我想要的是在我的delName()函数中添加一些东西,以便更新管道......

angular-pipe angular

10
推荐指数
2
解决办法
6120
查看次数

如何以角度反应形式访问表单控件和表单组

我想要pipe一个反应形式的表格组。

然后我想对这组单独的控件进行一些检查。

这是我定义表单的方式

  myForm = this.formBuilder.group({
    myFormNameDrop: this.formBuilder.group({
      myName:['',Validators.required],
      myDrop:['era']
    }),    
    style:[''],
    userId:[this.user_id]
  });
Run Code Online (Sandbox Code Playgroud)

这就是pipe我试图创造的

this.results = this.myForm.value.myFormNameDrop.valueChanges.pipe(      
  debounceTime(400),
  distinctUntilChanged(),            
  filter(formdata => formdata.myName.length > 0),
  switchMap( formdata => this.shoesService.details(formdata.myName)),
  shareReplay(1)
);//pipe  
Run Code Online (Sandbox Code Playgroud)

我有两个错误。 TypeError: Cannot read property 'pipe' of undefined有关this.results = this.myForm.value.myFormNameDrop.valueChanges.pipe(

并且 VS 代码显示有关以下内容的警告filter(formdata => formdata.myName.length > 0),myName类型上不存在属性'{}'

在这种情况下,我如何访问 formGroups 和 formGroups 的控件?我使用角度 6

谢谢

angular-pipe angular angular-forms angular6

10
推荐指数
1
解决办法
3万
查看次数

Angular 9 Keyvalues 管道不是为生产而构建的

我创建的应用程序在开发服务器 ng serve 上运行良好,但是当我尝试为生产构建时,它因此错误而失败

ERROR in src/app/leaderboard/leaderboard.component.html(9,17): Argument of type 'object' is not assignable to parameter of type 'Map<unknown, unknown>'
Run Code Online (Sandbox Code Playgroud)

这是我的排行榜.component.ts

import { Component, OnInit } from '@angular/core';
import * as firebase from 'firebase/app';
import 'firebase/firestore';


@Component({
  selector: 'app-leaderboard',
  templateUrl: './leaderboard.component.html',
  styleUrls: ['./leaderboard.component.css']
})

export class LeaderboardComponent implements OnInit {

  constructor() { }
  db = firebase.firestore();
  cities:object;
  suburbs:object;
  unsorted() { }
  async getCities() {
    await this.db.collection("Cities").orderBy('count', "desc").get()
    .then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            //console.log(doc.id, ": ", doc.data().count);
            this.cities[doc.id] = doc.data().count …
Run Code Online (Sandbox Code Playgroud)

html typescript angular-pipe angular

10
推荐指数
1
解决办法
1270
查看次数