AngularJS中的自动完成类型头

时间:2015-10-30 08:22:23

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

我在输入文本框中放置了Typehead,它显示了列表的下拉列表。但我希望当用户输入任何项目并且在列表中不可用时。通过单击“添加”按钮,它应弹出“无项目”...

请参阅

Code is here

var app = angular.module('myApp', ['ngAnimate','ui.bootstrap']);


 app.controller('NameCtrl', function ($scope,$http){




     $http.get("lib/data.txt").success(function(res){

  $scope.selected = undefined;
  $scope.states = res;

     });



         $scope.names = [];


        $scope.addName = function() {

if($scope.ww != '' ){

$scope.names.push({
     'x1':$scope.enteredName,
     'qty':$scope.ww,
     'p1':$scope.enteredName.p

    });

 $scope.enteredName = [];
 $scope.ww = '';
 $scope.tp = '';

}
else if ($scope.ww = '')
{

alert("hi");

} else {}




};

















        $scope.removeName = function(name) {
          var i = $scope.names.indexOf(name);
          $scope.names.splice(i, 1);
        };





      $scope.edit = function(name, idx){
        $scope.enteredName = $scope.states.find((item) => item.p === name.p1);
        $scope.sel = name.tp;
        $scope.ww = name.qty;
        $scope.names.splice(idx, 1);
      };


$scope.isCollapsed = true;






      });

1 个答案:

答案 0 :(得分:0)

您可以添加属性:typeahead-editable = false 如果条目不在列表中,这将使您的ng模型为空。然后,您可以管理一个空模型以添加“无项目”条目。

这里是文档:(默认值:true):它是否应该将模型值限制为仅从弹出窗口中选择的值?