

The next step here is to set up a Host Listener to ‘listen’ dynamically to any changes with regards to ‘window: resize’.

Setting up a Host Listener in your class to listen to any changes

See below, I have set the property that needs to be added in bold import from 2. Adding Host Listener to your project through the the first line of your page, add the following into the prefabricated import in line 1 (usually on a typical Angular home page). This is a quick win project and should be easy to implement if you are able to get an Angular web app up and running. If you are having this problem too on your Angular-based project, the answer is yes, it is possible to deliver this and I am going to show you how to do this dynamically using Host Listener. Is it possible to get the screen size or browser size in advance or dynamically, when the web app is being loaded to ensure the optimum UI/UX experience for your users? No matter on which device, or screen they are viewing your Angular web app from? While Angular has been built to be dynamic out of the box, the problem here is, you might want to customise certain viewing experiences, and the question is how can you tell where the site is being viewed from? In some cases, to provide an optimum UI/UX for your users, you might want to hide certain details when the user views your website on a mobile device rather than on a PC. This.Developing any web app-based project with Angular, in particular, requires you to assume that your user will be browsing your Angular project not only on a typical web browser on a PC but could also be viewed on an iPad or a mobile device. Import from ''Įxport class HighlighterDirective defaultColor: string = highlightColor: string = backgroundColor: string $ ng generate directive directives/highlighterĪbove command will create a new directive HighlighterDirective in the file src\app\directives\ // Run the following command in the terminal window to creates a directive in directives folder : To create a new directive we will use the generate command of ng cli. Let’s create a new Directive in the Angular application to demonstrate an element Highlighter directive which will include color input by a user and mouse events to highlight the background of a div. In this tutorial, we will create a custom directive example from scratch which will take user inputs from a directive element and use them in event listeners. Angular custom directives can take inputs using and add event listeners to elements using Angular post is compatible with Angular 4 upto latest versions, Angular 7, Angular 8, Angular 9, Angular 10, Angular 11, Angular 12 and Angular 13
