angularjscssangularjs-directiveangularjs-service

How to add a style tag to the head using angularjs directive


Hi I am allowing users to specify whether they want to print reports in a landscape or portrait format.

I was wondering if it's possible to add this (see below) into the head of the web document using a angularjs directive? That way it will change the printing size depending on the user input.

<style>@media print{@page {size: landscape}}</style>

Solution

  • This depends on whether you are going to be using this functionality in many different places. If you only need it once, then a directive may be overkill.

    You can simply put

    <style> @media print {@page { size: {{ orientation }} } }</style>

    within your angular controller, and specify orientation on the $scope.

    To my knowledge there is no need for the style tag to be in the head.