2017-02-18 75 views
0

你好我是從MD-選項試圖比如GET值:MD-選擇和MD-選項與如果

<md-select name="state" ng-model="currentUser.state" ng-change="selectChanged()" required> 
         <md-option value="Test">Test</md-option> 
         <md-option value="Test2">Test2</md-option> 
         <md-option value="Test3">Test3</md-option> 
</md-select> 

,我想借此

值:Test3的

$scope.selectChanged = function(){ 
    if ($scope.currentUser.state=="Test3"){ 
     $scope.curr_date = new Date(); 
    } 
    }; 

但這是行不通的。我如何獲得價值Test3來設置選擇的東西。

+0

嘗試在每個選項中將'value'更改爲'ng-value'。 –

+1

它應該工作 - https://jsfiddle.net/L8f1jLfh –

+0

不能使用ng值因爲我不能把它放入datebase – Radekesd

回答

0

它應該工作。你是否正確定義了你的控制器?我用你的代碼製作了一個fiddle - 它的工作原理。

請發佈完整的控制器代碼。

angular.module('MyApp', ['ngMaterial']) 
.controller('MyCtrl', function ($scope) {  
    $scope.currentUser = {}; 
    $scope.currentUser.state = {}; 
    $scope.selectChanged = function(){ 
     if ($scope.currentUser.state=="Test3"){ 
      alert('yay!'); 
    } 
    };  
})