2016-12-30 8 views
-1

入力ボックスの機能を実装する必要がありますが、$ httpから応答があったときにJSONが無効なので無効にできますそれ。

$scope.collections = function(val) { 
        return $http.get('/Documents/DocumentsList/', { 
         params : { 
          stk : val 
         } 
        }).then(
          function(response) { 
           if (response.data.suggestions) { 
            $("[uib-typeahead-popup].dropdown-menu").css('display','block'); 
            return response.data.suggestions 
              .map(function(item) { 
               return item.term; 
              }); 
           }; 
          }); 
       }; 

JSONレスポンス:

{} && { 
    "name": "John", 
    "age": 31, 
    "city": "New York" 
} 

無効なJSONを変更する方法VALIする方法下記

私は

uib-typeahead="name for name in collections ($viewValue)" 

角度ビューレベルのために使用していますd JSONを入力し、有効な応答を渡します。

+0

JSON? – Phil

+0

JSONレスポンスの 'suggestions'が表示されません。どのようにそれがまったく動作すると思いますか? – Phil

+0

@ Phil:はい、そうです。 JSONはactulaレスポンスではないJSONの唯一のサンプルフォーマット – CodeMan

答えて

1

ソースでの問題を修正する方が良いけど、あなたがそれを行うことができない場合は、独自の応答変圧器を実装し

それが有効であるので、あなたが実際のエンドポイント応答を修正しないのはなぜ
return $http.get('/Documents/DocumentsList/', { 
    params: { stk: val }, 
    transformResponse: function(data) { 
     return angular.fromJson(data.substring(6)); 
    } 
})... 
関連する問題