0

Hello everyone this is my first question on stack overflow

I am trying to make my application so when i push a button a value will be typed into a typeahead does anyone have a method of doing this?

Thank you

2
  • Welcome to Stackoverflow! Feel free to take a look at stackoverflow.com/help/how-to-ask Commented Jul 30, 2018 at 14:45
  • 1
    Thank you for the advice, i will follow it on my next question Commented Jul 30, 2018 at 21:10

1 Answer 1

1

Simply populate ng-model's value on click of a button using ng-click.

Here is an example:

var app = angular.module('myApp', ['ui.bootstrap']);
app.controller('myCtrl', function($scope) {
  $scope.data = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
  $scope.populate = function(index) {
    $scope.value = $scope.data[index || 0];
  }
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" />

<body>
  <div ng-app="myApp" ng-controller="myCtrl">

    <input type="text" ng-model="value" uib-typeahead="val for val in data | filter:$viewValue | limitTo:5" class="form-control">
    <button ng-click="populate(0)" class="btn btn-info">Populate</button>

    <pre>Value: {{value | json}}</pre>

  </div>
</body>
</html>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.