Angular App Not Working When Moving to Python Flask

2024/10/10 18:21:33

Not sure what information to give so will do as much as I can.

Currently have an Angular app sitting on IIS and using Classic ASP. All works fine. There is a dropdown which fetches some JSON that then populates a table.

Now, I have moved this over to Flask. When I select a dropdown and the table gets populated, I get an error saying:

TypeError: Cannot read properties of null (reading 'clientWidth')

The code is below

app.directive('widthSetter', function ($timeout) {return {restrict: 'A',link: function (scope, element, attr) {$timeout(function () {var el = attr.widthSetter + '_top'element.css({ 'min-width': document.getElementById(el).clientWidth + 'px' }) // ERROR HAPPENS HEREscope.$apply();});}}
});

My knowledge with Angular is severely limited. However, I can't see what has happened from Classic ASP to Flask to have made this happen.

There are no JS/Python errors when the app loads initially. Just when this one specific action happens.

The code snippet above looks like it tries to set the width of table cols/headers. When I inspect the code, I can see the below

<th id="id_top" ng-repeat="heading in dimensionDataHeading" ng-bind="heading | underscores" ng-if="$index < dimensionDataHeading.length-3" class="ng-binding ng-scope">id</th>

Has anyone got any suggestions? The table gets populated but the widths aren't set properly, presuming due to the above.

If I add

console.log(attr.widthSetter);

I get a list such as:

  • id
  • start_date
  • end_date
  • etc

Then I get an error for each one that was successfully logged to the console. When I did a console.log in the Classic ASP application, I get the same first list but (obviously) instead of a second list of errors, I got a second list identical to the first

Thanks,

PS

Answer

Python flask uses Jinja templates that use {{}} which is what AngularJS also uses so doing {{ '{{ variable_name }}' }} in the relevant places solved my issues

https://en.xdnf.cn/q/118426.html

Related Q&A

How can I subtract tuples in a list?

Lets say I have a list with tuples in it.Something like this:listnum = [(18,12),(12,20)]Is there a way I can subtract what is in the tuples and make listnum into:listnum = [6,8]As you can see It takes …

Chart barh matplotlib - overlap bars

Im new user of matplotlib and I have a problem with chart barh: overlap bars. When plot the graph, the bars draws overlapped and I havent found the reason. In my opinion the problem is on re-size the …

Python django image upload is not working

Python Django image upload is not working when I am adding data and click on submit button not give a any response and also not upload any data in the database.models.py fisrst of all i add model file.…

Android bluetooth send message working first time only

I need to send string message from Raspberry PI to Android device. I am getting message first time only. After that it does not work at all. I am using PYTHON code in Raspberry PI. After first time, it…

Scraping data from href

I was trying to get the postcodes for DFS, for that i tried getting the href for each shop and then click on it, the next page has shop location from which i can get the postal code, but i am able to g…

Numpy - how to sort an array of value/key pairs in descending order

I was looking at the problem Fastest way to rank items with multiple values and weightings and came up with the following solution, but with two remaining issues:import numpy as np# set up values keys …

How to extract certain under specific condition in pandas? (Sentimental analysis)

The picture is what my dataframe looks like. I have user_name, movie_name and time column. I want to extract only rows that are first day of certain movie. For example, if movie as first date in the ti…

Flask app.run method does not work with WinPython 3.11.1 and next.js application: fetch failed

When using WinPython 3.10.5 I am able to debug my flask & next.js application using the flask debug mode (to enable hot reloads): app.run(debug=True, host=host, port=port)However, when using WinPyt…

Pythonic way to assign global administrator roles for Azure Active Directory

What specifically needs to be changed in the Python 3 code below in order to successfully assign the Global Administrator role for an Azure Active Directory Tenant to a given service principal? We tri…

Pandas calculating age from a date

I really need help with this one. My previous post was very bad and unclear - Im sorry - I wish I could delete but hopefully this one will be better.I need to calculate the age based off of a date (se…