The UI in an angular directive is not getting refreshed due to issues with the

Check out this fiddle

http://jsfiddle.net/3jos4pLb/

I have a problem where my directive communicates with the parent controller scope by setting the finalValue. However, when the window is resized, the scope.finalValue updates in the console but the UI does not reflect this change. I want to continuously update this value on window resizing. Initially, the directive successfully overrides the set value of 5 (which represents the height of the window) and passes it to the parent controller. But as I resize the window, even though I see the scope.finalValue changing in the console, the UI remains unchanged.

var app=angular.module('App', []);

app.controller("Ctrl1", function($scope){
    $scope.finalValue = 5;
});
app.directive('elheightresize', ['$window', function($window) {
    return {
    restrict: "EA",
    scope: false,
        link: function(scope, elem, attrs) {
            scope.onResize = function() {
                    scope.finalValue = $window.innerHeight;
                console.log(scope.finalValue);
               // var header = document.getElementsByTagName('header')[0];
               // elem.windowHeight = $window.innerHeight - header.clientHeight;
               // $(elem).height(elem.windowHeight);
            }
            scope.onResize();

            angular.element($window).bind('resize', function() {
                scope.onResize();
            })
        }
    }
}])

Answer №1

When using jql to bind the resize event, keep in mind that jql operates at a low-level by directly binding the handler function to the element. This bypasses normal angular dirty-checking. To ensure that Angular is aware of non-angular event handlers, you must call scope.$apply() within your event handler. This notifies Angular that it needs to run a digest cycle.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

having trouble installing vue on macOS using npm

Here are the steps you should follow: Instead of using node v14+, switch to node v10+. (IMPORTANT) Add the following paths to your ~/.zshrc file (if you use zsh): /Users/[yourUsername]/.npm-packages/bin /Users/[yourUsername]/.npm-global/bin After ...

What is the best way to transfer a content script variable to a background script in a Chrome Extension?

I am looking to transfer a variable named "website_hostname" from the content script to the background script. This variable holds the hostname of the website you are currently visiting. Content Script: var website_hostname = window.location.href; //Cod ...

Retrieve data from a URL using Angular 6's HTTP POST method

UPDATE: Replaced res.json(data) with res.send(data) I am currently working on a web application using Angular 6 and NodeJS. My goal is to download a file through an HTTP POST request. The process involves sending a request to the server by calling a func ...

acquiring the main class instance within a function without relying on an arrow function

Within my Angular project, I have integrated a datatable with row grouping and row callbacks. Datatable Options openPositionDatatableOptions = { sDom: 'rt<"bottom"p>', ajax: (data, callback, settings) => { this.service.ge ...

javascript issue with showing content on click

I'm currently working on a school assignment where I am using the onclick() function to display information about an object. However, I am facing an issue where the information is not popping up as expected. HTML <!DOCTYPE html> <html> ...

Exploring the properties of individual Vue components on a single page with v-for loop

Struggling to render a Vue component in a Rails app by iterating through an array of data fetched via Ajax. The Slim template (index.html.slim) for the index page includes a custom_form_item component, where items represent custom forms data from Rails and ...

Issues involving the handleChange function in React can be a frustrating and common hurdle

I am encountering an issue with the handleChange function in my React project. Upon loading data from JSONPlaceholder and clicking on the 'Edit' button, a form is displayed with the selected user's information. However, when trying to edit ...

Jasmine has developed specifications that rely on a variable list size

Within my coding structure, I have a beforeAll function that navigates to the webpage and generates a list based on elements found on the page. The number of elements can fluctuate depending on user interaction with the UI. let variableList = [] beforeAl ...

Error in NodeJS when trying to run ESM: "ReferenceError: exports is not defined

Having a tough time with this task. I'm attempting to execute ESM scripts on Node 14 (AWS Lambda) I am working on running this piece of code to convert 3D objects to THREE JSON. This involves using the command node -r esm fbx2three.js model.fbx. I ...

Using kendo ng-delay in conjunction with a page refresh on a dropdownlist results in the list contents disappearing

As part of a learning exercise, I am in the process of rewriting a web app that originally used knockout and jQuery UI to now using kendo and angular. The issue I am facing involves a kendo-drop-down-list element that is populated with data from an ajax c ...

Utilizing Visual Studio: Implementing jsmin in post-build actions

After attempting to add jsmin.exe as a post-build event in my VS 2010 project, I encountered an "error code 9009" when building the project. I tested this in the command prompt and found that it works if I navigate to the folder and run: jsmin < debug ...

Tips for always focusing on a textarea within an Angular UI modal when opening the modal

I am facing an issue with setting focus to a textarea within an angular ui modal. I need the focus to be set when the modal is made visible, but it cannot happen during document load as it only works the first time the modal opens. Furthermore, the modal ...

Guide on integrating Materialize into an Angular 2 project

Currently in the process of transitioning from angular 1.5 to angular 2 for my latest project. While setting up the new app, I encountered an issue related to compatibility with a library. The library in question is angular2-materialize, but unfortunately ...

Error: Attempting to assign a value to 'onclick' property of null object [Chrome Extension]

window.onload = function() { document.getElementById('item_save').onclick = function() { var item_name = document.getElementById('item_name').value; var item_size = document.getElementById('item_size').value; v ...

Navigating to lower levels of JSON data in JavaScript instead of starting with the top level

Using a microservice, I fetch multiple sets of JSON data and display them on a Vue.js-powered page. The structure of the data is as follows: {"data":{"getcompanies": [ {"id":6,"name":"Arena","addr ...

Before installing npm packages, ensure to gracefully stop the process during pre-installation

Is there a way to stop the npm install process conditionally within a preinstall script? At the moment, I have a preinstall script named preinstall.js: if (someCondition) { process.kill(process.ppid, 'SIGKILL'); } The content of my package.js ...

Updating the React State is dependent on the presence of a useless state variable in addition to the necessary state variable being set

In my current setup, the state is structured as follows: const [items, setItems] = useState([] as CartItemType[]); const [id, setId] = useState<number | undefined>(); The id variable seems unnecessary in this context and serves no purpose in my appl ...

Observing a sessionStorage variable within AngularJS version 1.0.7

Is there a way to monitor a sessionStorage variable in AngularJS 1.0.7 without relying on a directive? For example: $scope.$watch("sessionStorage.getItem('OfferStore_items')", function() { console.log("New offer"); ...

What is causing the error message 'Unexpected use of 'location' no-restricted-globals'?

When working on my reactjs code, I encountered the following issue: const { children, location: { pathname }, } = this.props; let path = location.pathname; I am also utilizing the react router module in this component. Anyone have suggestions on how ...

AngularJS's support for html5mode on GitHub pages is now available

Is it feasible for GitHub pages to accommodate AngularJS in html5mode? I came across a source online suggesting that it can be done with a fallback page for 404 errors. However, this solution seems flawed as it may result in multiple 404 errors, which wou ...