3

I am working on angular js project in which we are using ng-repeat to display list of strings in cell template created using custom directives.

It working fine for list of numbers. But it does not works for list of strings.

You can try by changing number to string on plunker

var viewFn = "<div>View: <span ng-repeat='x in [1,2,3]'>{{x}}</span></div>";
...
var editFn = "<div>Edit: <span ng-repeat='x in ["Hi","Hello"]'>{{x}}</span></div>";

How can I get list of string using cell template?

2 Answers2

2

The problem is the string character that you are using.

You can avoid it using template literals (backtick char).

Change your template using it like:

var editFn = `<div>Edit: <span ng-repeat="x in ['Hi','Hello']">{{x}}</span></div>`;
Fabio Ruggiero
  • 309
  • 2
  • 7
  • Using backticks for the template is definitely cleaner-looking than having to escape characters when using double quotes. – angtlin Oct 03 '18 at 14:05
1

Because editFn is a string, the quotes in your ng-repeat array need to be escaped.

Try: var editFn = "<div>Edit: <span ng-repeat='x in [\"Hi\",\"Hello\",\"Hey\"]'>{{x}}</span></div>";

angtlin
  • 192
  • 1
  • 9