How to check if a method argument of a directive is specified in AngularJS?

Using ‘&?’ returns undefined if the attribute has not been set.

‘&’ = callback function is defined always.

‘&?’ = callback function is defined only when attribute is defined in html template.

bindToController: {
    callback: '&?'
},
controller: function() {
    if (this.callback === undefined) {
        // attribute "callback" was not defined
    }
}

Note: Works in Angular 1.4.8. I’m not sure if it works in older versions.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)