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.

Directive @ set to undefined on $scope after value set in link, new to v1.4.1 #12274

Closed
@johnculviner

Description

@johnculviner

This appears to be a regression caused by v1.4.1 (v1.4.0 does not exhibit the issue). Given a directive like this:

angular.module('testApp', []).directive('testDirective', function() {
  return {
    scope: {
      testAttr:'@'
    },
    template: '<div>$scope.testAttr = {{testAttr}}</div>',
    link: function(scope) {
      scope.testAttr = scope.testAttr || 'default value';
    }
  };
});

The expected behavior (and < v1.4.1 behavior) would be for 'default value' to be set on scope if it was undefined by the caller after the directive was done running.

The actual behavior in v1.4.1 is that

scope.testAttr

Is set to 'default value' for a period of time until it is overwritten to undefined.

Example of it NOT working in v1.4.1:
http://plnkr.co/edit/B3GKKO?p=preview

Example of it working in v1.4.0:
http://plnkr.co/edit/Y8W7Yw?p=preview

Digging into changes in v1.4.1 I think it might be related to:
71fc3f4
cc @lgalfaso

I believe setting a value to undefined after the fact when it was already set inside the framework isn't expected behavior at least it sent me and another few devs for a loop until we reverted from latest and the issue went away

Let me know if the v1.4.0 behavior is expected and I'll come up with a fix preserving @lgalfaso 's functionality if it truly is the culprit. Thoughts? Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions