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

Multiple ng-init declarations on same element

Open mprencipe opened this issue 12 years ago • 3 comments

I continuously use ng-init as a sort of variable declaration in templates, especially when formatting data for rendering. This nicely keeps view related things out of the controller.

When there is the need for multiple ng-inits but the DOM is relatively small the only (wrong) way is to create dummy elements just to contain the ng-init declarations. Currently Angular only evaluates one (the last one?) ng-init directive on one element, could it process multiple ones?

mprencipe avatar Sep 15 '14 18:09 mprencipe

You should be able to evaluate multiple expressions in ng-init by separating them with ; --- I was just looking at the parser code the other day, and it looks like that should work.

No promises because that code is terribly hard to follow, but I think you should give that a try and see if it does it for you.

caitp avatar Sep 15 '14 18:09 caitp

Worked like a charm, thanks! :)

mprencipe avatar Sep 15 '14 18:09 mprencipe

woooow Really thank you Catip

RaniaSalah avatar Aug 11 '16 20:08 RaniaSalah