請幫助我在這一點上。角度1.5分量檢查'&綁定'爲空
我有使用「&結合」的角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)
所有這些測試總是返回「真」,即使回調未獲通過。
敢肯定你可以改變'「和」'爲'「?&」',然後你會看到'ctrl.onSomething === null' – abyx