请在这一点上帮助我。
我有一个使用'& binding'的角度1.5组件:
app.component('foo', {
bindings: {
message: '<'
onSomething: '&'
},
template:'<div>blah blah</div>',
controller: function () {
var ctrl = this;
ctrl.myOperation = function () {
ctrl.onSomething(); // <= look this!
}
}
});
我想测试是否定义了“onSomething”。
事实上,如果我这样使用它:
<foo message='my message' on-something='doSomething()'></foo>
一切正常。
但是如果我以这种方式使用它:
<foo message='my message'></foo>
'onSomething' 不应该被定义,但我无法检查它!
我试过了:
if (ctrl.onSomething) ...
if (ctrl.onSomething == undefined) ...
if (ctrl.onSomething == null) ...
if (angular.isDefined(ctrl.onSomething)
所有这些测试总是返回“真”,即使回调没有通过。