Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use multiple lines in Angular attributes?

Tags:

angularjs

Is is possible to include a newline in an Angular JS expression in an attribute tag? Something like this:

<p ng-repeat="
    foo in foos 
    | filter:{attr: 'something really long'} 
    | orderBy:bar">
  {{foo}}
</p>

EDIT: To clarify, the above doesn't work. I was wondering if there is some other syntax that allows for breaking this kind of expressions into multiple lines.

like image 387
Michał Bendowski Avatar asked Oct 25 '13 12:10

Michał Bendowski


2 Answers

angular.js parser would be able to handle it, but there's a quick regex check before handing it to the parser (see http://docs.angularjs.org/error/ngRepeat:iexp):

Be aware, the ngRepeat directive parses the expression using a regex before sending collection and optionally id to the AngularJS parser. This error comes from the regex parsing.

I filed a bug to loosen this restriction: https://github.com/angular/angular.js/issues/5537, you can hand-patch it in the meantime, it's just 1 character: m (/regex/m).

like image 86
TWiStErRob Avatar answered Oct 05 '22 01:10

TWiStErRob


It is possible for an expressions to span multiple lines. But ng-repeat throws an error if you try to span the expression on multiple lines.

Take a look at this plunker: Add a new line in the ng-repeat expression and open the browser console to see the error message.

http://plnkr.co/edit/E1O8Iy3VzL3kzj72BDUL?p=preview

like image 36
bekite Avatar answered Oct 05 '22 01:10

bekite