2016-08-12 60 views
2

我想设置一些默认值为单选按钮,因为应该选择特定单选按钮的值。为此,我在(controlDirectives.js)文件中创建了一个指令radioControlDir。如何在单选按钮上调用指令来设置Angular Js中的值

function controlDir() 
{ 
    return { 
     transclude: true, 
     restrict: 'E', 
     scope: { 
      ngModel: '=', 
      queObj: '=' 
     }, 
     link: function (scope, element, attrs) 
     { 
      if(angular.isUndefined(scope.ngModel)) 
      { 
       scope.ngModel = 'Y'; 
      } 
     } 
    }; 
} 

scope.queObj._pageAttributes.defaultValue有如果ngmodel没有价值将被设定值。其他文本和选择指令工作正常。

回答

1

我认为这只是因为你有限制值'E'这意味着元素。

它应该是'A'(属性);

而在摔跤手queObj._pageAttributes.defaultValue是“”,但对于无线电,你需要将它设置为这个收音机的值,如'Y';

function radioControlDir() 
    { 
     return { 
      transclude: true, 
      restrict: 'A', 
      scope: { 
       ngModel: '=', 
       queObj: '=' 
      }, 
      link: function (scope, element, attrs) 
      { 

       if(angular.isUndefined(scope.ngModel)) 
       { 

       scope.ngModel = 'Y'; 
       } 
      } 
     }; 
    } 
相关问题