Q:

how to prevent selecting typeahead in some cases in angularjs

In the below type head function isPaymentALreadyExist return true or false based on result the option shold be selected
<input type="text" ng-model="paymentObj.loan" typeahead="loan as loan.customer.idlbl + '-' + loan.customer.name for loan in loansList | filter:$viewValue" typeahead-on-select='isPaymentAlreadyExist(paymentObj.loan)'/>

A:

Change:
typeahead-on-select='isPaymentAlreadyExist(paymentObj.loan)'

To:
typeahead-on-select='isPaymentAlreadyExist($item, $modal, $label)'

And change your $scope.isPaymentAlreadyExist() function accordingly to clear the model in case the payment already exists. Another option will be to create your own filter which will remove payments that already exist from the list inside your type-ahead.

