NetanelBasal
12/3/2016 - 9:41 PM

unique.js

<body ng-controller="MainCtrl as ctrl">
    <ul>
     <li ng-repeat="recipient in ctrl.recipients">
      {{recipient}}
     </li>
    </ul>
    <input type="text" placeholder="Recipient" ng-model="ctrl.recipient"/>
    <button ng-click="ctrl.addRecipient(ctrl.recipient)">Add recipient</button>
</body>

app.controller('MainCtrl', function($scope) {
  this.recipients = [];
  this.recipient = '';
  
   this.addRecipient = (recipient) => {
    const exists = this.recipients.indexOf(recipient) > -1;
    if(!exists) {
      this.recipients.push(recipient);
    }
   }
});