2016-11-30 100 views
0

我收到一个错误,当我包含另一个指令,我做错了,请帮助。 下面是我收到指令通信时出错

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

我的两个指令中的错误: -

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如何,我打电话给他们。

 <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); 

      } 
     } 
    }; 
});