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.

Controller prototype / instance methods #321

Closed
@vojtajina

Description

@vojtajina

There is a different this (inside controller method - different scope object), if method is defined in instance than if defined in prototype. And the method is invoked from child scope element (i.e. element created by repeater).

At least we should mention that in doc, as it's bit confusing.

There is a gist with example: https://gist.github.com/907914

Reason

Prototype methods are binded, so that they are always called with root (for given controller) scope as this. See https://github.com/angular/angular.js/blob/master/src/Scope.js#L583
Instance methods (defined in constructor) are only applied, so that they are called with related scope as this. (that's child scope inside repeater)

Possible solution

Unify the API - do we need to bind the prototype methods ??? I hope we don't.
User has to access parent scope through $parent or $root property.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions