我有一个带有可选'&'的组件结合。
如何通过此绑定检查方法是否已传递到组件中?
假设:
bindings: {
onChange: '&?',
}
当我运行if (this.onChange)
时,它总是评估为一个角度包装器(因此是真的):
ƒ (locals) {
return parentGet(scope, locals);
}
我读了这个post并尝试检查if (this.$attrs.onChange)
,但这也不起作用。 $attrs.onChange
评估为:
if (this.$attrs.onChange) {
console.log(this.$attrs.onChange) // $resolve.onChange()
console.log(typeof this.$attrs.onChange); //string
}
我做错了什么?在Angular 1.5.8上运行
答案 0 :(得分:0)
您可以检查传递的onChnage的类型是否为以下函数:
typeof this.onChange === 'function'