你如何检查和放大器;变量在指令设置 [英] How do you check if & variable is set in directive
本文介绍了你如何检查和放大器;变量在指令设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一个指令,在那里你通过ARG设置方法回调,说:
In a directive, where you set a method callback through an arg, say:
<my-directive callback='showAlert()' />
您可以通过检索的范围在返回设置变量:
You can retrieve the variable through the scope setting in the return:
scope: {
callback: "&callback"
}
如果回调不设置,例如:
If the callback is not set, eg:
<my-directive />
$ scope.callback的值仍然是:
The value of $scope.callback is still:
$scope.callback():function (locals) {
return parentGet(scope, locals);
}
有没有检查回调没有设置好办法?
Is there a good way to check that the callback was not set?
推荐答案
我能想到的一个方法是检查指令名称的属性参数,如
One way i can think off is to check the attribute parameter for the directive name like
link: function (scope, elm, attrs) {
if(attrs.callback) {
//this attribute has been defined.
}
}
这篇关于你如何检查和放大器;变量在指令设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文