How do I filter an array with AngularJS and use a property of the filtered object as the ng-model attribute?

前端 未结 8 1439
刺人心
刺人心 2020-11-30 19:17

If I have an array of objects, and I want to bind the Angular model to a property of one of the elements based on a filter, how do I do that? I can explain better with a con

8条回答
  •  一个人的身影
    2020-11-30 19:43

    If you are using ES6 you can:

    var sample = [1, 2, 3]
    
    var result = sample.filter(elem => elem !== 2)
    
    /* output */
    [1, 3]
    

    Also take notice filter does not update the existing array it will return a new filtered array every time.

提交回复
热议问题