Using AngularJS in local HTML - angularjs

What are the best practices for using AngularJS in local HTML? By that, I mean HTML files opened directly from the local file system, not from a web server.
I have had some luck in replacing partials that are in separate files with partials within script tags. And replacing Ajax calls with including JS files that contain the JSON data. However, I wondered if there are any guidelines for doing this, or even helper libraries?
BTW, my use case is a desktop application that generates HTML reports that are server using a local web server. In some cases users want to create a ZIP file that contains an HTML report, which they can email to someone else. Given the sensitivity of these reports, people may have objections to using a cloud service. Having HTML in a zip file gives them control of their data.

Related

problem when read files from local computer in pyscript

When I run the Python file, the file works correctly, but when I run the Python file with the script, it gives an error in read txt file(file not found).
how can i solve this problem؟
Software written in any language (Python, JavaScript, WASM) cannot access local files directly. This is a browser security restriction. The browser can access files on behalf of your application using the <input type="file"> DOM element link.
In Python and JavaScript, you must provide the user with a file input selector. The user selects the file and your application can the retrieve the file data from the browser.
In JavaScript this functionality is implemented with the FileReader class. This class can be used in Python via the create_proxy() function to proxy event callbacks.
If you are just getting started with Pyscript, I have written a number of articles link.
See this issue report.
Code running in a webpage is sandboxed and can't freely access files on the computer hosting the browser.
(It would be a terrible security problem if just visiting a webpage would give the author of the page access to your files).
If you want to access a file on the user's computer, use <input type="file"> and have the user select it. I don't know if you can access it directly or if you would need to use a JavaScript FileReader and then pass the results from JS to PyScript … but one of those two approaches should be possible.

What is the difference between downloading the AngularJS Script for an HTML file and just referenceing the script off of ajax.googleapis.com?

In certain tutorials and applications (e.i. codeschool) I see that the HTML file includes AngularJS with a simple script tag reference to "angular.min.js", whereas in others (e.i. w3schools), the script tag references "http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js". Is the latter just to get around having to download AngularJS? If you were going to deploy a website using AngularJS, is there a correct way to refer to the angular script (download or no download)?
Referencing to e.g. /assets/js/angular.min.js means loading Angular from your disk because you saved this location somewhere in your project. When you reference it from a CDN or some other hosting, it is downloaded from this resource, once the .html page is called.
Yes, the CDN version gets you around downloading and storing it yourself.
There is no correct way how to refer to Angular as a library but there are quite some.
However, most popular for productive applications is having a build script, that knows how to look for your scripts on your disk, concatenate them, minify them and reference them in one local file. This ensures downloading only one file that is as small as possible to save performance.
Syntax below is used to attach JS Externally
<script src=""></script>
if src="abc.js" it means it is on the same server as html file
if src="http://example.com/abc.js" it means it is loaded from CDN

Don't know how to convert an Angular Web App made with nodejs to windows exe

I'm a complete noob at programming with nodejs.
I'm developing an webapp with angularjs with this structure:
So, when I run the command "nw ." with the prompt command my application loads correctly.
All I want now is transform all this structure on an single Windows executable for distribute it for my customers.
I'm looking for any solutions like Bat to Exe, APPJS, and a lot of others. But I do not have any success either.
How can I do this?
You are probably going to need to looking at use a tool like ng-template to build everything into a single package or distributing a basic web server along with your site in order to make things work.
This is mainly due to the issue with the browser not allowing XHR requests from disk as AngularJS runs and request the various html files as your views change.
The best thing is to look using a tool like ng-template to compile all of the html partials into a single .js file that can be loaded from disk along with your AngularJS app. This way AngularJS will load all your partials into the $template cache and won't have to make any XHR calls to load them.
The other possibility is to look at something simple like the Cassini Web server or something similar that you can add to your directory and launch with a simple batch file. I say this because you are talking about distributing something to people who may not have Node.js installed, meaning you probably can't rely on them being able perform a bunch of installs just to get to your app.
How to package and distribute your apps solved my problem!

Read property file on both java and angularjs

I'm using a properties file in project. I want to read the properties file both java and angularjs. suggest me a best location to place the properties file which can accessible by java and also by angularjs.
By design it should be src/resources folder.
Well by opportunity, it can be placed in webapp too.
From what I know angularjs is meant to execute on browser. I do not recommend downloading properties into browser as web assets similar to css/js. So I would recommend keeping properties in src/main/resources/. If you need, host a small rest end point giving these properties as a json map in response. This can be used by angularjs on client side(browser)
Ideally properties which have confidential information shoild never be sent to browser.
Any one can get access to those information by debugging in tools like chrome,etc.
Sending such information should not create problems for your system. In those cases you shld hv 2 properties in src/ resources folder. One contains db passwords etc. Other with open information.

Change Angularjs existing backend to Play 2

I have a fully developed Angularjs frontend app (with the routes and everything set up) and would like to change the current backend to a Play 2 Java. What is the best approach to display the existing html files from Angular in Play? I have found a few examples of how to connect the routes, but I would rater not create an index.scala.html file as I would like to have the two frameworks separated as much as possible and having Play only working as backend.
If you don't want to dynamically generate views from Play using Twirl and you just want to serve your HTML static files publishing them as assets is the way to go. By default assets are designed to provide resource like CSS or JS files but nothing prevents you from serving ordinary HTML views as well.
Simply put your index.html in the public directory and modify the conf/routes files so it can handle all requests:
GET /*file controllers.Assets.at(path="/public", file)
This way your index.html will be accessible at www.yourdomain.com/index.html. Remember to put this line as the last mapping in the file as it matches all possible URLs. Other services should be declared above it.

Resources