Sunday, 3 November 2019

When to use templateUrl instead of template in angular?


Template and templateUrl are the properties which are used with as a decorator with component. When we create a new component, we can write our html code inline or in an external file. It is recommended when the html code is more than three line use an external file for writing html code as it is easy to maintain.

In the below we have used templateUrl to call an external html file.



In the below we have used template and all html code is written inline. To write multiple line use backtick character instead of single coat.



In the same way we can use style and styleUrls. If you are using inline style, see the below code

styles  ['table { color  #369; font-family  Arial, Helvetica, sans-serif; font-size  large; border-collapse  collapse;}''td {border  1px solid black; }']

The same can be written in a separate .css file and can be decorated with styleUrls at component.ts file.

No comments:

Post a Comment