2017-08-18 8 views
-1

ngModelは、私はMD-選択する選択ボックスを使用しようとしているが、NG-モデルが動作していないよう

$scope.callFunction = function() { 
 
    console.log($scope.modelData); 
 
}
<md-select ng-model="modelData" ng-change="callFunction()"> 
 
    <md-option ng-repeat="x in tempData" ng-value="x">{{x}} 
 
    </md-option> 
 
</md-select>

を働いていません。私がどこに間違っているのか?

ng-change関数の出力は定義されていません。

+0

私の回答はあなたに役立つでしょうか? –

+0

コントローラにバインドしましたか? – Edric

答えて

1

使用$scope.modelData代わりにのみmodelData

$scope.modelData; 
 
$scope.callFunction = function() { 
 
    console.log($scope.modelData); 
 
}
<md-select ng-model="modelData" ng-change="callFunction()"> 
 
    <md-option ng-repeat="x in tempData" ng-value="x">{{x}} 
 
    </md-option> 
 
</md-select>

+0

申し訳ありませんが、それはタイプミスでした。私は自分のコードで$ scopeを使用しましたが、それでも動作しません。 –

+0

そしてあなたのデータで '$ scope.modelData'を定義しましたか?あなたの完全なコードを共有してください。 –

0

のそれは"undefined"をログに記録されていますか?おそらくモデルはあなたがコントローラ機能で$スコープを追加する必要がコントローラ$scope.modelName

// sometime data might not bind for object in that case you to declare this not always 
 
$scope.modelName; 
 
$scope.callFunction = function() { 
 
    console.log($scope.modelName); 
 
}
<md-select ng-model="modelName" ng-change="callFunction()"> 
 
    <md-option ng-repeat="x in tempData" ng-value="x">{{x}} 
 
    </md-option> 
 
</md-select>

1

とのより良い動作します。

angular.module('test') 
    .controller('TestController',['$rootScope','$http','$scope', 
     function ($rootScope,$http, $scope) { 
      $scope.callFunction = function() { 
      console.log($scope.modelData); 
     } 
}]) 
0

$scope経由でアクセス可能ですconsole.log($scope.modelData);

関連する問題