Storing View Templates in HTML Files

Currently, the view templates are strings inside our JavaScript. This might be okay if we have a single small view, but as we create more components and have to manage more views, it will be increasingly difficult to keep them as strings. The trailing backslashes and general clunkiness of managing view code in JavaScript is something that’s best to avoid.

Fortunately, Webpack makes this easy. With Angular 1, which was used in the previous edition of this book, you had to install a special Rails plugin to convert your templates into something the asset pipeline could serve up. Now, we need to bring in the HTML as a string and pass that string to the template: key when declaring our components. Doing this ...

Get Rails, Angular, Postgres, and Bootstrap, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.