2016-08-13 4 views
0

AngularJS selected localyticsドロップダウンからオプションを選択すると検出しようとしています。ここでAngularJS - 選択されたローカライゼーションが機能しない

は、ドロップダウンのためのコードです:

<select chosen data-placeholder="Buscar..." 
    class="w-100" 
    ng-model = "medSearchType" 
    ng-change = "changeMedSearch(medSearchType)"> 
     <option value="Medicamento">Medicamento</option> 
     <option value="Componente">Componentes Activos</option> 
</select> 

そして、私のコントローラで私は、次の機能があります。

$scope.changeMedSearch = function (searchType) { 
    console.log(searchType); 
} 

をそれは細かい初めて動作しますが、私は別のオプションを選択する場合コンソールで次のエラーが表示され、ドロップダウンで選択したい他のオプションが選択されません。

未知の型エラー:pを設定できませんroperty 'selected' of undefined

どうすればこの問題を解決できますか?

ありがとうございます。

答えて

-1

私はMrJSinghのアドバイスや使用NG-オプションに続くが、問題はまだ起こりました。

私は空を添加し、それが最終的にはまだ同じエラーを

<select chosen data-placeholder="Buscar..." 
    ng-model = "medSearch" 
    ng-change = "changeMedSearch(medSearch)" 
    ng-options = "size as size for size in medSearchTypes"> 
    <option></option> 
</select> 
+0

なぜ空のオプションタグが必要なのか分かりません。あなたの作業コードを投稿できますか? –

-1

代わりにng-optionsを使用してください。

angular.module("app",[]).controller("ctrl",function($scope){ 
 
    $scope.items = [1,2,3,4,5,6] 
 
    $scope.changeMedSearch = function(medSearchType){ 
 
     alert(medSearchType) 
 
    } 
 
    })
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <title>JS Bin</title> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script> 
 
    
 
</head> 
 
<body ng-app="app" ng-controller="ctrl"> 
 
    <select ng-model = "medSearchType" 
 
    ng-change = "changeMedSearch(medSearchType)" ng-options="size as size for size in items" 
 
    ng-model="item" ng-change="update()"></select> 
 
</body> 
 
</html>

+0

を働いていた私はそれが動作選ばれたディレクティブを奪うが、私はそれがディレクティブで –

+0

AHAする必要がある場合は、その後、別のがありますあなたは$ scopeを使うことができます$ watch –

+0

@FerVargas [この回答を見てください](http://stackoverflow.com/questions/24754005/how-to-implement-an-ng-change-for- a-custom-directive) –

関連する問題