当我包含另一个指令时出现错误,我做错了什么请帮忙。 这是我收到的错误
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>
这段代码有没有错误,谁能帮忙,谢谢? 我对这个指令有点困惑。
最佳答案
如果遇到指令 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);
}
}
};
});
关于javascript - 指令通信时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40881424/