Jake
Jake

Reputation: 53

Tag input from object array only add specific item to model (ng-tags-input)

Is it possible, as is, to only add a specific item form the array to the model? For example, from the object array demo:

$scope.tags = [
    { id: 1, name: 'Tag1' },
    { id: 2, name: 'Tag2' },
    { id: 3, name: 'Tag3' }
  ];

Is it possible to only add the "id" to the model?

$scope.tags = [
    { id: 1 },
    { id: 2 },
    { id: 3 }
  ];

Upvotes: 2

Views: 1417

Answers (1)

JustinDSN
JustinDSN

Reputation: 61

The ng-model is required, but you could disregard it and assign it to a dummy variable. Then use onTagAdded function to add the an object containing the $tag's id property to your model's tag's array.

From the documentation:

onTagAdded - Expression to evaluate upon adding a new tag. The new tag is available as $tag.

function onTagAdded($tag) {
    $scope.tags.push({id: $tag.id});
}

Upvotes: 1

Related Questions