0.0.1 • Published 7 years ago

angular-cherry-pick v0.0.1

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
7 years ago

What is this?

This is nearly equivalent as follows.

<ANY ng-repeat="option in options|filter:{id:selectedId}:true">{{option.title}}</ANY>

Use case

In a controller, some array defined.

$scope.options = [
  {id:1, title:'foo'},
  {id:2, title:'bar'},
  {id:3, tille:'baz'}
]

In a template, a drop-down list uses the defined array.

<select ng-options="option.id as option.title for option in options"
  ng-model="selectedId"></select>

And, render a element as title' property notid' property.

{{options|cherrypick:{id:selectedId}:'title'}}

Usage

Add the module to your application.

angular.module('myApp', ['ngCherryPick']);

Add the filter to a binding.

{{mylist|cherrypick:{id:100}:properyName}}

Why does not bind a object, but a id.

Because the world is complex...

Of course, You can goes on a simple way.

<select ng-options="option as option.title for option in options"
  ng-model="selected"></select>

{{selected.title}}