angular / angular.js

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

Make props accessible without bindings, inspired by React #13698

Open dmitriz opened 8 years ago

dmitriz commented 8 years ago

Having seen how easy it is to access Props in React, I can't help to request the same awesome feature in Angular:

<awesome-comp name="'Trump'"></awesome-comp>

I would dream to avoid the clunky binding declarations and have the same level of simplicity:

.component('awesomeComp', {
    template: '<div>You are awesome, Mr. {{$comp.$props.name}}</div>',
})

Opinions?

toddmotto commented 8 years ago

Like this idea a lot. However, one thing I think is more beneficial here comes from React's propTypes inspiration as well:

This example makes an assumption that two-way binding is assumed:

.component('counter', {
    bindings: {
        count: angular.scopeType.number
    },
    template: '<div>Count: {{counter.props.count}}</div>',
})

And maybe another idea to implement type validation and binding info:

.component('counter', {
    bindings: {
        count: ['=', angular.scopeType.number]
    },
    template: '<div>Count: {{counter.props.count}}</div>',
})
gaui commented 8 years ago

:+1:

valorkin commented 8 years ago

Already possible in angular 2 http://victorsavkin.com/post/119943127151/angular-2-template-syntax

petebacondarwin commented 8 years ago

This is yet another reason to start the upgrade to Angular 2.

toddmotto commented 8 years ago

@petebacondarwin Indeed! Excited for those changes. Some form of support for 1.x apps could potentially be considered though, especially large enterprise apps that will gradually be making code upgrades to get closer and closer to 2 as possible before leaving 1.x!

dmitriz commented 8 years ago

@valorkin Does Angular 2 allow the same props-syntax without controller? I could not find it in that article.

valorkin commented 8 years ago

@dmitriz no controller - no problem :) it is available for directives and components

dmitriz commented 8 years ago

@valorkin Would you mind giving a more detailed description of what you have in mind? How would you implement the above proposals in Angular 2? I don't see it without controller.

petebacondarwin commented 8 years ago

This is similar to #11657 Moving to the ice box for the moment as this is low priority right now.

LulzAugusto commented 8 years ago

Please, take into consideration not wrapping functions when implementing that feature. That would be helpful in scenarios like the one below and to everyone migrating their controllers to isolated components: http://stackoverflow.com/questions/34958681/what-is-the-best-way-to-pass-functions-between-inner-components-in-angularjs-1-5

petebacondarwin commented 8 years ago

@LulzAugusto - I don't understand your use case. Can you respond to my comments on SO?

LulzAugusto commented 8 years ago

@petebacondarwin I just edited the question. Thanks for your help

linhuiw commented 6 years ago

Does angular 4+ version has this feature? @dmitriz @LulzAugusto