2014-05-21 19 views
0

我正在創建幾個指令(驅除,填充空白,翻譯)。如何繼承指令中的某些屬性

<exercises mode='register' data="rows"> 
    <fill-in-the-gaps></fill-in-the-gaps> 
    <translations></translations> 
</exercises> 

我需要知道如何繼承指令中的一些屬性(模式,數據)孩子(填補空白,翻譯)?

回答

0

您最好的選擇可能是在exercises指令以使用控制器和掛那些屬性那裏,然後通過require帶來控制器:

app.module('foo').directive('exercises', function(){ 
    return { 
     restrict: 'E', 
     controller: function($scope, $attrs) { 
     self = this 
     $attrs.$observe('mode', function(value){ // use $scope.$watch here if you 
               // want actual scope values 
      self.mode = value 
     }) 
     } 
    } 
    }) 

    app.module('foo').directive('fillInTheGaps', function(){ 
    return { 
     restrict: 'E', 
     require: '^excercises', // require a parent directive 
     link: function($scope, $element, $attrs, excercisesCtrl) { 
     console.log(excercisesCtrl.mode) 
     } 
    } 
    }) 
+0

這個例子是好的,因爲執行console.log(excercisesCtrl.mode)返回rigi值(註冊),但ng-show返回false。 template is fillInTheGaps