检查角度中md-select的变化

时间:2018-01-26 19:46:53

标签: angularjs

我正在尝试检查md-select中的更改,但我无法使用$dirty

来实现
     <div class="resourceForm" ng-form="resForm{{$index}}">
         <md-select name="resourceAllocForm" id="id{{resourceContent.activityId}}-{{x}}" ng-model="selRes[$parent.$index][x]" placeholder="Select Resource" class="md-no-underline" ng-keyup="resourceCheck($parent.$index)">
           <md-option ng-value="resource.id" ng-repeat="resource in resourceList track by resource.id">{{resource.roleProLabel}}</md-option>
        </md-select>
     </div>

我尝试过这样的事情

$timeout(function(parentIndex){
   $scope.resourceAllocForm['resForm' + parentIndex].$dirty;
   console.log('Form Edited');
}

1 个答案:

答案 0 :(得分:1)

你需要这样的东西,

<md-select ng-change="show(resource)" ng-model="selectedresource">
   <md-option ng-repeat="resource in resourceList track by resource.id" value="{{resource.id"}}">{{resource.roleProLabel}}
   </md-option>
<md-select>

并在控制器中

$scope.show = function(resource){
  console.log(show);
}