2016-08-01 103 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

要使輸入空白,只需將空字符串分配給輸入模型。使用寫入所有邏輯的控制器的範圍。我編輯了答案並添加了一個例子。 –