2014-09-10 58 views
1

我創建了一個指令,表明這樣的壓延機:繼承angularjs在所有子功能elemts

app.directive('noeDatepicker', ['$parse', 'datetimeService', function ($parse, datetimeService) { 
    return { 
     restrict: 'E', 
     templateUrl: '/app/directives/templates/datepicker.html', 
     scope: { 
      model: '=', 
      withisrequired: '@' 
     }, 
     require: '^form', 
     replace: true, 
     link: function (scope, element, attrs, ctrl) { 
      scope.buttonId = 'date_icon_' + attrs.id; 
      scope.inputId = 'date_input_' + attrs.id; 
      scope.cancelId = 'date_cancel_' + attrs.id; 

      setTimeout(function() { 
       Calendar.setup({...}); 

     } 
    }; 
} 

});

和我的模板是這樣的:

<div ng-model="model" class="form-inline"> 
    <input id="{{inputId}}" class="form-control" type="text" isrequired="{{withisrequired}}" ng-model="model" placeholder="1111/01/01" /> 
    <img id="{{cancelId}}" src="/Content/noe/assets/image/icon/Cancle.svg" width="22" height="22" /> 
    <img id="{{buttonId}}" src="/Scripts/jalalijscalendar/cal.png" /> 
</div> 

,但我的問題是,當我想例如添加NG-只讀到這個指令,它只是添加只讀屬性DIV元素和輸入元素是不是隻讀和它接受來自用戶的輸入(見代碼波紋管):

<noe:datepicker model="viewModel.date" id="date1" name="date1" ng-readonly="true" /> 

我想這NG-只讀功能也使所有子元素div標籤只讀並不僅僅是添加只讀proptety到div元素!

我該怎麼做?

+0

Checkout [this](http://stackoverflow.com/questions/25258651/validate-the-rating-directive-in-angularjs/25259439#25259439)爲驗證自定義控件的解決方案。 – 2014-09-10 09:25:08

+0

你可以做一個演示? – dfsq 2014-09-10 09:48:14

回答

1

更新noeDatepicker與

範圍:{ 只讀: '= ngReadonly', ... }, 模板:<div> <input ng-readonly="readonly"/> </div> ...

基本上,你需要爲孩子添加NG-只讀元素,你想要設置。