angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.81k stars 27.5k forks source link

Add ng-prop-* to one-way bind an expression to arbitrary element properties #10072

Closed ewinslow closed 9 years ago

ewinslow commented 9 years ago

ng-prop-* could take an expression and bind to arbitrary properties:

ng-prop-checked="some.expression"

This would be similar to the current ng-attr-*:

ng-attr-x="{{interpolation}}"

Reasoning:

  1. Angular 2.0 is going this sort of direction. So this will help ease migration. Migration pain is one of the main complaints right now for 2.0, it seems to me.
  2. Get the benefits of the Angular 2.0 approach without waiting 1.5 years.
    • ng-prop-* would always takes an expression, so it's clear what format the right hand side should be, regardless what property is being modified
    • ng-prop-* would work on all properties (like ng-attr-*), even from custom web components
    • etc.?
  3. (Minor) Provides nice symmetry from jQuery API to Angular API: $.fn.prop and $.fn.attr
  4. Binding to arbitrary properties requires custom compiler support to recognize all ng-prop-* attributes without explicitly adding each as separate directives, so this is why I think it belongs in core.
lgalfaso commented 9 years ago

Even when angular 2 is moving in this direction, I am not sure this is something that we want to push for 1.x. The reason being that (at least for me) the security side-effects are not clear. Eg, can you bind to innerHtml? If yes, can you add a Githubissues.

  • Githubissues is a development platform for aggregating issues.