Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiline template in directive definition

I am trying to make a directive template multiline. Is this possible?

myApp.directive('myDir', function() {
return {
    restrict: 'E',        
    template: '<div>
                |Hello,
                |{{test}}!
                |</div>'
    };
});

Here's a Fiddle to see what I mean.

like image 863
igor Avatar asked Apr 17 '14 06:04

igor


People also ask

How would you define an inline template in angular component with multiple lines?

An inline HTML template for a component is defined using template config in @Component decorator, as shown below. It can be a single line template wrapped inside double quotes or single quotes. It can also be a multi-line template wrapped inside backticks char `.

Which of the following HTML element is valid in angular template?

Almost all HTML syntax is valid template syntax. However, because an Angular template is part of an overall webpage, and not the entire page, you don't need to include elements such as <html> , <body> , or <base> , and can focus exclusively on the part of the page you are developing.


2 Answers

Use "\" at the end of each line.

myApp.directive('myDir', function() {
return {
    restrict: 'E',        
    template: '<div>\
                |Hello,\
                |{{test}}!\
                |</div>'
};

Here's you Fiddle

like image 82
Amir Popovich Avatar answered Oct 22 '22 08:10

Amir Popovich


You can simply use graves instead of single quotes

myApp.directive('myDir', function() {
  return {
    restrict: 'E',        
    template: `<div>
        Hello, 
        {{test}}!
        </div>`
  };
});
like image 25
Archie Archbold Avatar answered Oct 22 '22 08:10

Archie Archbold