zoukankan      html  css  js  c++  java
  • [Angular 2] Pipe Purity

    Explaining how Pipes only change by default when your Pipe input parameters change and not when your data changes. It also shows you how to make an “unpure” pipe if you always want your pipe to update.

    import {Pipe} from 'angular2/angular2';
    
    @Pipe({
        name: 'startsWith'
    })
    
    export class StartsWith{
    
        transform(value, [field, letter]){
            return value.filter((item) => {
                return item[field].startsWith(letter);
            })
        }
    }

    Current Pipe only watch for [field, letter] changes, not value changes.

    The way to tell pipe also watch for value changes is just add 'pure: false':

    import {Pipe} from 'angular2/angular2';
    
    @Pipe({
        name: 'startsWith',
        pure: false
    })
    
    export class StartsWith{
    
        transform(value, [field, letter]){
            return value.filter((item) => {
                return item[field].startsWith(letter);
            })
        }
    }
  • 相关阅读:
    sklearn库学习笔记1——preprocessing库
    juypter notetbook
    信用卡欺诈
    matplotlib1
    python一行输入多个数
    pandas数据预处理
    pandas基础用法
    numpy简单用法2
    numpy 简单用法
    简单循环
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4926645.html
Copyright © 2011-2022 走看看