2016-11-30 6 views
0

別のディレクティブを追加したときにエラーが発生しました。私はそれらを呼び出していますかディレクティブ通信中にエラーが発生しました

1)

app.directive('mthelp', ['$parse', '$http','$filter', function ($parse, $http,$filter) { 
    return { 
     restrict: 'AE', 
     scope: {}, 
     templateUrl: 'dropDownTable.html', 
     controller : function ($scope) { 
      console.log(element); 
      this.tests = "s"; 
     } 
    } 
}]); 

2)

app.directive('getf', function() { 
    return { 
     require: 'mthelp', 
     scope: {}, 
     link: function (scope, element, attr, mthelpCtrl) { 
      console.log(element); 
      if(event.which === 114 || event.which === 32) 
      { 
       console.log(mthelpCtrl.tests); 

      } 
     } 
    }; 
}); 

私のhtml - :ここに は、私が

Error:- [$compile:ctreq] Controller 'mthelp', required by directive 'getf', can't be found! 

私の2指示を受けています何のエラーです。

 <div class="form-group"> 
      <label class="col-sm-3">FirstName</label> 
      <div class="col-sm-9"> 
       <input type="text" getf ng-model="firstText" hpcode="1"> 
      </div> 
     </div> 


    <div class="col-xs-4 pull-right" mthelp donotapply=true></div> 

このコードに間違いがありますか、誰かが助けてくれますか、ありがとうございますか? 私はこの指示のことで少し混乱しています。

+1

'require: 'mthelp'、' getfとmthelpディレクティブが同じ要素に属していることを前提としています。これはそうではありません。 – estus

+0

yaa ohk私はそれを行いますが、テンプレートは両方私がしたくない要素バインドを取得??私はそれのために何をすべきですか? –

+0

テンプレートが両方の要素にバインドされるのはどういう意味なのか分かりません。 – estus

答えて

0

mybeにこの指令が必要な場合やそうでない場合がある場合は、このように任意に設定してください。

app.directive('getf', function() { 
    return { 
     require: '?mthelp', // add ? before directive name 
     scope: {}, 
     link: function (scope, element, attr, mthelpCtrl) { 
      console.log(element); 
      if(event.which === 114 || event.which === 32) 
      { 
       console.log(mthelpCtrl.tests); 

      } 
     } 
    }; 
}); 
関連する問題