I am new to Angularjs and want to know can we use angularjs in .ejs files for writing client side applications. Also, can we write both angularjs and nodejs files in the same .ejs file? I will be grateful for any further guidance.
The best way is to render the index page from server and then use angularjs local routing to load templates.
Related
This question already has an answer here:
Angularjs suitable moment to launch a http request when app start
(1 answer)
Closed 7 years ago.
I have an Angular app running on Express 4.0 and I would like to send some information to the front end on startup, when the index file is served but I didn't manage to figure out on which route I should do this.
Thanks!
I think you are looking for angular.module('...').run(). Here's the documentation on modules in angular. See the section on Module Loading & Dependencies. Also note you can only inject instances (not Providers) into .config and .run blocks.
Use NgInit
<div ng-init="names=[{data: 'a'},{data: 'b'}]"></div>
With that line in the html you will have in the controller the $scope.names object so you can do whathever you want with that.
Put that data in the ng-init directive using one of the templates engines that express has.
You can use the AngularJS $http service to make a GET request on an express route, wich gives you some json with the data you are trying to use in your front end.
Ok so I have looked around and cannot find the exact answer I am looking for. When developing a Sails app (which I am new to) it appears that by default it creates its own frontend using EJS.
Is this correct?
If this is correct then why is there an npm for sails generate frontend
If I want to use an Angular frontend is sails-generate-frontend-angular the best route to go?
Thanks!
First you need to separate server templating (EJS) from angular.
Just because sails defaults to an EJS template engine does not mean that you can not still put angular is your asset library and create and angular app. EJS is (the default but not the only option) what sails uses as a programming language for building its templates on the server that then get delivered to the client. Angular templates are used once delivered to the client to display information and perform tasks specifically already in the client machine.
1.) See above
2.) Sails-generate-frontend helps to setup your asset pipeline. It creates grunt tasks to copy image files and setup your javascript libraries such as ANGULAR.js, jQuery ect for use in your front-end.
3.) It could be. It depends, what a lot of people do is setup 2 projects. They use Sails as their API and then setup a second project for their Angular app (especially if its a SPA).
If instead your just using angular is specific places in your app (think jQuery style), then you would use a something like generate-front-end to take the angular library from someplace (like bower_compenents) and place it in your assets when you lift your app. It also makes it avaiable so that it can be placed in your html to be included in your app.
I on the other hand, use sails templates (I use Jade instead of EJS) to create and modify my angular templates on the server before they reach the client. This is a slightly advanced practice and can get confusing if you don't understand the difference between generating html on the server vs client.
An alternate method of thinking about this would be creating your index page on the server. This page would include your css and scripts. It would possibly be the only page on your server and everything else would be angular templates rendered on the client asking for JSON calls. In this scenario you would be using SAILS (ejs, or jade or whatever) to render only a single page INDEX.js and that might be the only server template you have.
However, this being said. Sails ships with this stuff already. You don't need sails-generate-frontend. Its is already inside a standard sails app.
Can any share an example of using Angularjs and Pdfkit to save a file to the client downloads? I've got it rendering in the same window as the app, but need it as a pdf file. I'm assuming this is all done client side rather than the server side with the Pdfkit node module.
This solution can help you https://www.npmjs.com/package/ng-pdfkit, it's a An Angular wrapper for PDFKit.
I´m trying to integrate a Blueimp Jquery File Upload plugin in my application.
My application has an AngularJS front-end running in a Node.js server and a Rails API backend running in a WEBrick server.
I would like to clarify which is the best practices to store the files? In Angular (this case Node.js) server or the Rails one.
Thanks,
Roberto.
I'm working on an app that has the exact same layout as yours and I came to the same question.
Since I'm trying to separate the back-end and front-end completely and have all the work with the db and files done in the back-end, I found that it's better to save the files in Rails server. That also gives you an option to do background operations with files (using sidekiq, for example), without making users wait for completion in the front-end.
There are lots of tools for file upload from angularJS to the server (Rails), but I personally found angular-file-upload directive easiest to understand and implement. I recommend you check it out.
I hope it helps,
Ulugbek
The problem I want to solve is how to inject a separate html file into the main one in JavaFX Webview + AngularJS. I tried to use AngularJS ngInclude, but maybe there is a better way to achieve it? Ater debugging AngularJS ng-include I failed due to unsupported jar:// protocolol. Is there any way to load html files using AngularJS framework and JavaFX? HTML files are inside the jar file and AngularJS is the framework. Should I turn away from one of them or there is some solution?
Details:
I load from index.html subpage1.html using nginclude dircetive. It works outside JavaFx but fails when I use Webview inside JavaFX.