Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

directives with isolated scope and a optional function '&?' should be returned as undefined if the function is missing #6404

@davidemoro

Description

@davidemoro

Overview of the issue

It is not a bug, probably just a design issue about directives with isolated scope and optional functions passed via '&?'.

If you don't pass any function to the directive, you get a function that returns undefined instead of undefined.

Errors

No errors are thrown.

Motivation for or Use Case

If you declare a scope property as optional, probably the expected behaviour is getting undefined if you try to access this property.
This is exactly what happens when you have a '@?' binding and you don't fill in the optional attribute: you get undefined trying to access $scope.property.

The way to understand if there is a function parameter is inspecting the attrs.
So this seems a special case not motivated for '&?'.

Angular Version(s)

All versions, no regression.

Browsers and Operating System

All browsers and operting systems.

Suggestion

In order to get a common behaviour for optional parameters you could just add the following control to

case '&':
:
if (optional && !attrs[attrName]) {
return;
}

If you find that this proposal is ok I can make a pull request from: https://github.com/davidemoro/angular.js/blob/master/src/ng/compile.js

I've just run the tests and all seems fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions