2016-08-01 124 views
0

我想提出一个自定义typehead角度引导用户界面,这里是我的自定义模板:NG点击不工作

<script type="text/ng-template" id="customTemplateall.html"> 
     <a> 
      <span ng-bind-html="match.label | uibTypeaheadHighlight:query"></span> 
      <br> 
      <small>Nama Lain:{{match.model.tag}}</small> 
     </a> 
</script> 

因此,与该代码我想提一些结果之后用户在输入字段中键入一些字符,这里是输入域代码:

<div class="wrp-search"> 
     <div class="labelsearch"><img src="images/bulb-black.png" alt=""/> Tulis Jenis Pemeriksaan</div> 
     <input type="text" ng-model="$parent.nama" placeholder="Contoh: Diabetes" uib-typeahead="item as item.name for item in dataall | filter:{tag:$viewValue} | limitTo:10" typeahead-min-length="2" typeahead-template-url="customTemplateall.html"> 
     <input type="submit" class="btn-green" ng-click="cari()" /> 
</div> 

所以,我想有多个搜索结果,例如像:1 MG Labs

所以当用户点击打印头时,它会转到多个结果,当用户单击“GO”时,它会直接显示结果。

有什么我必须做的?

更新:

这里是myController的范围:

$scope.onSelect = function ($item, $model, $label) { 
     $scope.$item = $item; 
     $scope.$model = $model; 
     $scope.$label = $label; 
      // alert($scope.$item.name); 
      $http({ 
       method: 'POST', 
       url: '/api/v1/order/cart/add/byname', 
       data: { 
       name: $scope.$item.name 
       } 
      }).success(function(){ 
       // $window.location.href = 'order/pemeriksaan'; 
       $scope.cartget(); 
       $scope.nama.name = ""; //this is the code 
      }).error(function(){ 
       alert("pencarian gagal"); 
      }) 
     }; 

回答

1

您可以使用角UI的引导提供了以下功能:

$scope.onSelect = function ($item, $model, $label) { 
    //$scope.$item = $item; 
    //$scope.$model = $model; 
    //$scope.$label = $label; 

}; 

此功能将运行时用户从前面选择任何选项。所以你可以打开一个模式来显示多个结果。

下可以找到的预输入设置此功能标题这里: http://angular-ui.github.io/bootstrap/#/typeahead

例子:

$scope.onSelect = function ($item, $model, $label) { 
    var id = $item.id; 
    // This function opens a modal 
    // You could also create an alert 
    $scope.getMarketPlayerID(id); 
    // This statement clears the input to blank 
    $scope.selected = ""; 
}; 
+0

你好,感谢你的精彩回答。我只是想知道,我必须使用其范围这样做...在文档中,它不告诉我每个$ item,$ model,$ label或$ event ...的功能,并且你会介意给我一个例子,只给出警告任何事情我点击了? –

+0

嗨,问题解决了,我只需要取消注释你已经完成了...我只想知道如何使用户点击他/她想要的搜索表单为空... –

+0

要使输入空白,只需将空字符串分配给输入模型。使用写入所有逻辑的控制器的范围。我编辑了答案并添加了一个例子。 –