Isolate scope directive with optional ampersand binding in angularjs?

Paul

Can one create a isolate scope with optional ampersand (parent context) data binding?

scope: {
  myMethod: '&?'
}

If the directive is implemented without assigning myMethod, there is no error. However, I see that when the optional property is not assigned, angular assigns it a noop function anyways. Therefore, there appears to be no way to know, within the directive, if the implementer assigned the optional property a method or not.

link: function (scope, element, attrs) {
 scope.myMethod(); //this calls a noop function instead of being undefined, as i exected
}

Any insights? I'd like to know if the implementor has assigned the optional property.

DRiFTy

Check the attrs object to see if it was populated:

link: function (scope, element, attrs) {
    if (attrs.myMethod) {
        scope.myMethod();
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Optional two-way binding on isolate scope for Angular Directive

From Dev

Angular directive check if optional binding is set in isolate scope

From Dev

AngularJS Directive Isolate scope behavior

From Dev

Two way data binding with directive and isolate scope

From Dev

Returning a promise from isolate scope directive with `&` binding

From Dev

AngularJS : Directive not able to access isolate scope objects

From Dev

Binding directive scope with controller in AngularJS

From Dev

AngularJS : Modify model of parent scope in a directive with '=xxx' isolate scope?

From Dev

AngularJS scope variable won't persist inside a directive with isolate scope

From Dev

AngularJS scope variable won't persist inside a directive with isolate scope

From Dev

How to get two way data binding in a directive *without* an isolate scope?

From Dev

How to get two way data binding in a directive *without* an isolate scope?

From Dev

Directive Isolate Scope 1.2.2

From Dev

isolate scope in directive undefined

From Dev

" =? " in Angular Directive Isolate Scope

From Dev

isolate scope in directive undefined

From Dev

Angularjs + directive Isolate two way data binding not working

From Java

what's the meaning of '=?' in angularJS directive isolate scope declaration?

From Dev

AngularJS - Access isolate scope when using "controller as" syntax in directive

From Dev

AngularJS : ng-repeat over custom directive with isolate scope

From Dev

Angularjs, Directive, ampersand

From Dev

AngularJS - binding a function to an isolate scope via '&', not firing on ng-click

From Dev

AngularJS isolate scope: & vs =

From Dev

Isolate scope fallback in AngularJS

From Dev

directive isolate scope not triggering $watch

From Dev

Accessing the isolate scope of a compiled directive

From Dev

AngularJS: Parent scope is not updated in directive (with isolated scope) two way binding

From Dev

Angular two-way data binding isolate scope directive but property is undefined?

From Dev

Is the angular scope binding &(ampersand) a one time binding?

Related Related

  1. 1

    Optional two-way binding on isolate scope for Angular Directive

  2. 2

    Angular directive check if optional binding is set in isolate scope

  3. 3

    AngularJS Directive Isolate scope behavior

  4. 4

    Two way data binding with directive and isolate scope

  5. 5

    Returning a promise from isolate scope directive with `&` binding

  6. 6

    AngularJS : Directive not able to access isolate scope objects

  7. 7

    Binding directive scope with controller in AngularJS

  8. 8

    AngularJS : Modify model of parent scope in a directive with '=xxx' isolate scope?

  9. 9

    AngularJS scope variable won't persist inside a directive with isolate scope

  10. 10

    AngularJS scope variable won't persist inside a directive with isolate scope

  11. 11

    How to get two way data binding in a directive *without* an isolate scope?

  12. 12

    How to get two way data binding in a directive *without* an isolate scope?

  13. 13

    Directive Isolate Scope 1.2.2

  14. 14

    isolate scope in directive undefined

  15. 15

    " =? " in Angular Directive Isolate Scope

  16. 16

    isolate scope in directive undefined

  17. 17

    Angularjs + directive Isolate two way data binding not working

  18. 18

    what's the meaning of '=?' in angularJS directive isolate scope declaration?

  19. 19

    AngularJS - Access isolate scope when using "controller as" syntax in directive

  20. 20

    AngularJS : ng-repeat over custom directive with isolate scope

  21. 21

    Angularjs, Directive, ampersand

  22. 22

    AngularJS - binding a function to an isolate scope via '&', not firing on ng-click

  23. 23

    AngularJS isolate scope: & vs =

  24. 24

    Isolate scope fallback in AngularJS

  25. 25

    directive isolate scope not triggering $watch

  26. 26

    Accessing the isolate scope of a compiled directive

  27. 27

    AngularJS: Parent scope is not updated in directive (with isolated scope) two way binding

  28. 28

    Angular two-way data binding isolate scope directive but property is undefined?

  29. 29

    Is the angular scope binding &(ampersand) a one time binding?

HotTag

Archive