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.

cannot create two directives on the same element with "scope"attributes and 'bindToController:true' #10888

Closed
@drpicox

Description

@drpicox

Hi,

I know that two directives cannot create a new isolated scope on the same element because of design principles (I understand and I think that such behaviour is correct).

In the Angular 1.3.X there is a new option in compiler which is bindToController:true which allows to bind attributes to the directive controller instead to the scope. In such case two directives with two different controllers can share the same scope but having its respectively attributes binded to each controller. Ex:

(In this case I have to use $attrs.$observe manually. )

What's the problem and so what I think that it can be improved: scope: { ... } is useful because it saves lot of code to syncronize and parse attributes (ex: '@' for $attrs.$observe, ...), and it is great to be reused to initialize controller attributes, but, the problem is that it also creates a new isolated scope (new and isolated), when in fact probably is not our objective (we have the controller encapsulating the state).

My proposal: if bindToController is true and scope: { ... } it does not creates a new isolated scope. In such case a new scope (but not isolated, ex scope: true, http://jsfiddle.net/drpicox/hozt6zrw/1/ ) should be the best option.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions