当我包含另一条指令时,我收到错误,我做错了请帮忙。 这是我收到的错误
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>
此代码中是否有任何错误,有人可以帮忙吗,Thanku? 我在这个指令中很少混淆。
答案 0 :(得分:0)
尝试将它设置为可选的。
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);
}
}
};
});