2016-08-12 53 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'; 
       } 
      } 
     }; 
    } 
相關問題