相关疑难解决方法(0)

管道''找不到angular2定制管道

我似乎无法修复此错误.我有一个搜索栏和一个ngFor.我试图使用这样的自定义管道过滤数组:

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

import { User } from '../user/user';

@Pipe({
  name: 'usersPipe',
  pure: false
})
export class UsersPipe implements PipeTransform {
  transform(users: User [], searchTerm: string) {
    return users.filter(user => user.name.indexOf(searchTerm) !== -1);
  }
}
Run Code Online (Sandbox Code Playgroud)

用法:

<input [(ngModel)]="searchTerm" type="text" placeholder="Search users">

<div *ngFor="let user of (users | usersPipe:searchTerm)">
...
</div>
Run Code Online (Sandbox Code Playgroud)

错误:

zone.js:478 Unhandled Promise rejection: Template parse errors:
The pipe 'usersPipe' could not be found ("
<div class="row">
    <div  
    [ERROR ->]*ngFor="let user of (user | …
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular2-pipe angular

97
推荐指数
5
解决办法
12万
查看次数

Angular2 innerHtml绑定删除样式属性

我的问题,当我使用innererHtml绑定时 - angular2删除所有样式属性.这对我来说很重要,因为在我的任务中 - html是在服务器端生成的,具有所有样式.例:

@Component({
  selector: 'my-app',
  template: `
    <input type="text" [(ngModel)]="html">
    <div [innerHtml]="html">
    </div>
  `,
})
export class App {
  name:string;
  html: string;
  constructor() {
    this.name = 'Angular2'
    this.html = "<span style=\"color:red;\">1234</span>";
  }
}
Run Code Online (Sandbox Code Playgroud)

但是在DOM中我只看到1234而且这个文本不是红色的.

http://plnkr.co/edit/UQJOFMKl9OwMRIJ38U8D?p=preview

谢谢!

styles angular

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

标签 统计

angular ×2

angular2-forms ×1

angular2-pipe ×1

styles ×1