angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

Allow nested hash objects in isolate scope option

Open qualidafial opened this issue 11 years ago • 6 comments

I propose enhancing the scope option parameter for directives, to support binding to nested properties in isolate scopes:

scope: {
  model: {
    value: '=ngModel'
  }
}

This would provide an avenue for directive implementations to set up bindings on a nested property, where they can be safely bound from child scopes of the isolate scope, e.g. ngTransclude or ngIf.

See http://stackoverflow.com/questions/26459958/how-to-reconcile-angulars-always-use-dots-with-ngmodel-rule-with-isolate-scop for context.

qualidafial avatar Oct 20 '14 07:10 qualidafial

I was going to say that this should be an idea for Angular v2 but this form of isolated scope definition is going away in v2 so it would be handled in an entirely different way.

petebacondarwin avatar Oct 20 '14 09:10 petebacondarwin

Just as a followup, the simplest solution I found was to just inline the directive that was using ng-transclude into the directive that invoked the former, which eliminated the extra scope, at the expense of markup duplication.

qualidafial avatar Oct 20 '14 21:10 qualidafial

Actually, how about supporting it through:

scope: {
  'model.value': '=ngModel'
}

Probably simpler to implement and consistent with Angular expression handling. Though doing the following would probably have undefined behavior:

scope: {
  model: '=something',
  'model.value': '=ngModel'
}

chrisirhc avatar Dec 12 '14 23:12 chrisirhc

Not actually simpler --- less usable to do it that way, and also a breaking change.

caitp avatar Dec 12 '14 23:12 caitp

Yea, it'll break users that depend on properties containing . in them, which in my opinion would be rare, but in that respect it's a breaking change.

chrisirhc avatar Dec 12 '14 23:12 chrisirhc

On further thought, you're right. The OP's suggestion is better.

chrisirhc avatar Dec 12 '14 23:12 chrisirhc