Modify the scope in the middle of a scope function

UPDATE: I've created a JSFiddle: http://jsfiddle.net/U3pVM/18137/

I'm looking to make the black section move up FIRST, followed by the green sliding across. I'm struggling to achieve this effect. Keep reading for more details:


Note: The code is written in Typescript (re: () => {} )

The situation involves a webpage with an overlaying div and a few divs in the background. It indicates the type of animation through a CSS class.

https://i.sstatic.net/BOFBd.png

Below is the code snippet referenced in the diagram:

$scope.Resizing = true; // This stops animations (linked to a css class)
$scope.MoveToPage( col, row );
$scope.$applyAsync(() => { 
    $scope.FirstPageTop = -$scope.PageMap.WindowInfo.Height; 
    $scope.Resizing = false; // Enable animations 
});

The behavior I'm aiming for is:

  • When Resizing is true, it removes the animation class.
  • Then it executes the MoveToPage method, adjusting the position without animation due to the Resizing attribute.

This is reflected in my HTML:

<div class="column-wrap" 
            ng-class="{ 'column-wrap-animation' : !Resizing }" 
            ng-style="{ 'width': PageMap.ContainerWidth + 'px',
                        'left': PageMap.ColumnWrap.Left + 'px'}">

This process updates the scope asynchronously (to avoid errors) and removes the overlay after positioning the underlying content. The issue is that the overlay slides off before the content underneath reaches its destination. How can I address this CSS animation conflict?

Alternatively, why isn't the class being removed when Resizing is set to false and the scope is updated as indicated?

Providing more context:

Answer №1

If you encounter the $scope.$apply problem, one solution is to utilize setTimeout:

http://jsfiddle.net/U3pVM/18138/

$scope.Resizing = true;
$scope.MoveToPage( col, row );
setTimeout( function() {
    $scope.FirstPageTop = -$scope.PageMap.WindowInfo.Height;
    $scope.Resizing = false;
    $scope.$apply() // Remember to include this line
}, 1);

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

Tips for receiving a reply from a post request

After successfully making and completing a post request, I'm wondering about using console.log(res.valor) in the code to display the data: consultarCorreio(){ this.cartS.cart.valorTotalItems this.cartS.getCorreiosPrazoPreco(this.cartS.cart.pesoTot ...

Comparing strings in AngularJS

Struggling to compare two strings in AngularJS, I've come across various examples online. From what I understand, there are different methods like angular.equals(str1, str2), ===, and == if you're certain both are strings... Despite trying all t ...

Having issues with Craco not recognizing alias configuration for TypeScript in Azure Pipeline webpack

I am encountering an issue with my ReactJs app that uses Craco, Webpack, and Typescript. While the application can run and build successfully locally, I am facing problems when trying to build it on Azure DevOps, specifically in creating aliases. azure ...

What is the process for configuring vue.config.js with typescript?

Just starting out with typescript and running into an issue while configuring vue.config.js const webpack = require("webpack"); module.exports = { plugins: [ new webpack.DefinePlugin({ __VUE_I18N_FULL_INSTALL__: true, __ ...

Step-by-step guide on building a personalized rxjs operator using destructured parameters

I am in the process of developing a unique RxJS filter operator that requires a destructured array as a parameter. Unfortunately, TypeScript seems to be throwing an error related to the type declaration: Error TS2493: Tuple type '[]' with a len ...

AngularJS - Increase the input date by 6 hours before converting it to JSON

Is there a way to add 6 hours to an input date in AngularJS? I attempted the following code: var eventStart = new Date ($scope.event.startdateid); var startDate = new Date ( eventStart ); startDate.setHours ( eventStart.getHours() + 6 ); event.startdate ...

How to selectively hide the menu button in Ionic framework when not within the <ion-view> element

Within the framework of Ionic, my goal is to dynamically hide the menu button based on certain conditions. However, due to other constraints, I had to separate the menu into its own controller to avoid completely re-rendering the menu and header bar every ...

Angular CLI - exploring the depths of parent-child component communication

My issue revolves around accessing the 'edit' method of a child component using @ViewChild, but for some reason it's not functioning as expected. Where could I possibly be going wrong? Here are the console logs: https://i.sstatic.net/wvpVN ...

Issues with Karma's base path functionality

I am encountering issues with launching tests using Karma for the first time. My folder structure is as follows: node_modules -angular-mocks src -compiled -lib -tests -karma.conf.js Within my karma.conf.js file, these are my file list and basepat ...

Trouble displaying AngularJS $scope.data in the HTML code

I'm experiencing an issue where the data received from a POST request is being logged in the console, but is not displaying on the HTML page. Despite having a controller set up, the {{user}} variable is not appearing on the HTML page. While I can se ...

What's the best way to ensure my translations are preloaded in Angular-Translate before being accessed in my controller?

Exploring Angular Translate has presented me with a hurdle. I am attempting to utilize translations within my controller, however, the code in my controller executes before the translation is fully loaded. Below is an excerpt of my code: var myApp = angul ...

Error in React Router when using TypeScript

Encountering errors while trying to set up router with React and TypeScript. https://i.sstatic.net/muSZU.png I have already attempted to install npm install @types/history However, the issue persists. Your assistance would be greatly appreciated. Thank y ...

Accessing files from various directories within my project

I'm working on a project with 2 sources and I need to import a file from MyProject into nest-project-payment. Can you please guide me on how to do this? Here is the current file structure of my project: https://i.stack.imgur.com/KGKnp.png I attempt ...

How can I use angular-ui bootstrap's typeahead feature to pull data from a JSON file and populate two separate input fields with the retrieved values

I implemented an autocomplete feature using a json file in an input field. The json file contains multiple attributes, and I want to display different attributes in separate input fields. For example, one input should show the "driver_name" and another inp ...

Top technique for verifying the presence of duplicates within an array of objects

How can I efficiently check for duplicates in typescript within a large array of objects and return true or false based on the results? let testArray: { id: number, name: string }[] = [ { "id": 0, "name": "name1" }, ...

Constructing an extensive modular application using the AngularJS and RequireJS framework

I'm embarking on the creation of an extensive Modular Web App using AngularJs and RequireJS. Here is the directory structure I envision: |--index.html |--css |--images |--libs | └--angular.js | └--angular-route.js | └--require.js | |--js | ...

"Loop through an array using forEach leads to a subscription that

I am a beginner in Angular and struggling to understand how async functions work. I have written the following code, but I am encountering an error: GET https://localhost:44353/api/ecams/id/undefined 400 and ["The value 'undefined' is not va ...

Get every possible combination of a specified length without any repeated elements

Here is the input I am working with: interface Option{ name:string travelMode:string } const options:Option[] = [ { name:"john", travelMode:"bus" }, { name:"john", travelMode:"car" }, { name:"kevin", travelMode:"bus" ...

The Error message "Property 'data' is not present in Type <void> | AxiosHttpResponse<any>" is indicating that the data property is missing on

When I fetch data for a specific user, I have a promise that I use to setState. Below is the implementation: getUserUsername = (): string => { const { match } = this.props; return match.params.username; }; onFetchUser = () => getUse ...

Creating and experimenting with AngularJS applications (and applications overall)

I am currently working on developing an app, following the trend of using a REST API for the back-end and Angular (previously Backbone and jQuery) for the front-end. Initially, stubbing the REST API for testing purposes is straightforward; however, as deve ...