0

I need to manually (or automatically) change detect property of object in array. I have array of productShops entity in ngFor loop which is filtered by "isNotDeleted" property. When I change value of isNotDeleted property angular does not detect change.

<ul class="nav nav-tabs">
    <li *ngFor="let productShop of product.productShops | filter:'isNotDeleted':true" >
        <a href="#categoryAssocTab{{productShop.shop.id}}" data-toggle="tab">{{productShop.shop.name}}</a>
    </li>
</ul>

EDIT: Pipe implementation:

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

@Pipe({
    name: 'filter'
})
export class FilterPipe implements PipeTransform{

    transform(value:Array<any>, property, equal){

        let properties = property.split('.')

        if(value){
            return value.filter(item => {

                let finalValue:any = item

                properties.forEach(p => {
                    finalValue = finalValue[p]
                })

                return finalValue == equal
            })
        }

        return []
    }

}
6
  • Please add your pipe implementation Commented Nov 13, 2016 at 9:14
  • Added implementation of the filter pipe. Commented Nov 13, 2016 at 9:16
  • How do you change property? Commented Nov 13, 2016 at 9:19
  • By two way binding <switch name="isDeleted [(ngModel)]="productShop.isNotDeleted" /> Commented Nov 13, 2016 at 9:20
  • stackoverflow.com/questions/39757603/… Commented Nov 13, 2016 at 9:22

1 Answer 1

1

Your pipe should be marked as not pure, because the result of its transformation for a given input can change even though the input hasn't changed.

@Pipe({
    name: 'filter',
    pure: false
})

See also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.