pug

Actual use of Jade template and angularjs

爱⌒轻易说出口 提交于 2019-11-26 22:55:00
问题 I am building a website using nodejs and express. How to make divisions in a page dynamic? Is Jade used for that? if not how to do it?what is angularjs used for? Please help i searched a lot on google and i couldn't get a clarity in the usage of them. 回答1: Jade creates the html used in the browser on the server-side . The browser executes a request to the web-server, the web-server executes Jade, which will generate the html that will be sent to the browser. This server-side content

how to render json object in jade and loop through results

…衆ロ難τιáo~ 提交于 2019-11-26 22:44:10
问题 When I send a JSON string to a jade file for rending I'm only able to print out the string in it's entirety but not by it's elements. How do I print out specific elements or loop through the JSON string? app.js: var http = require('http'), express = require('express'), net = require('net'); var app = express(); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.logger('dev')); app.use(express.static(__dirname + '/public')); app.get('/', function (req, res)

ExpressJS 3.0 How to pass res.locals to a jade view?

流过昼夜 提交于 2019-11-26 22:38:17
问题 I want to display a flash message after a user fails to sign in but I just can't get the variables to show up in my Jade views. I have some pieces, I know I have to use this in my app.configure(): app.use (req, res, next) -> res.locals.session = req.session And I'll set what the flash message is after the user POSTS the wrong password: exports.postSession = (req, res) -> users = require '../DB/users' users.authenticate(req.body.login, req.body.password, (user) -> if(user) req.session.user =

AngularFire - Remove Single Item

房东的猫 提交于 2019-11-26 21:53:32
问题 Here is the relevant code in my view: p(ng-repeat="t in todos") input( type="checkbox", ng-model="t.done", ng-click="clearItem($event)" ) {{t.text}} done? {{t.done}} When the checkbox is clicked, I want the appropriate object in the todos array to be removed from the database. My clearItem function is as follows: $scope.clearItem = function(event) { todoRef.remove($scope.t); } However, this removes all the entries in my database. I want it to remove only the specific object in question. Is

How can I get Express to output nicely formatted HTML?

蹲街弑〆低调 提交于 2019-11-26 21:17:57
When using Express for Node.js, I noticed that it outputs the HTML code without any newline characters or tabs. Though it may be more efficient to download, it's not very readable during development. How can I get Express to output nicely formatted HTML? In your main app.js or what is in it's place: Express 4.x if (app.get('env') === 'development') { app.locals.pretty = true; } Express 3.x app.configure('development', function(){ app.use(express.errorHandler()); app.locals.pretty = true; }); Express 2.x app.configure('development', function(){ app.use(express.errorHandler()); app.set('view

Use a variable in a Jade include

强颜欢笑 提交于 2019-11-26 19:52:25
I'm working with Jade and Express and I would like to use a variable in my include statement. For example: app.js app.get('/admin', function (req, res) { var Admin = require('./routes/admin/app').Admin; res.render(Admin.view, { title: 'Admin', page: 'admin' }); }); layout.jade - var templates = page + '/templates/' include templates When I do this I get the error EBADF, Bad file descriptor 'templates.jade' I even tried include #{templates} to no avail. AFAIK JADE does not support dynamic including. What I suggest is to "include" outside the template, i.e. app.js app.get('/admin', function (req

How to pass variable from jade template file to a script file?

一曲冷凌霜 提交于 2019-11-26 19:22:20
I'm having trouble with a variable (config) declared in a jade template file (index.jade) that isn't passed to a javascript file, which then makes my javascript crash. Here is the file (views/index.jade): h1 #{title} script(src='./socket.io/socket.io.js') script(type='text/javascript') var config = {}; config.address = '#{address}'; config.port = '#{port}'; script(src='./javascripts/app.js') Here is a part of my app.js (server side): app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(__dirname + '/public')); }); app.configure(

Passing objects to client in node + express + jade?

陌路散爱 提交于 2019-11-26 18:58:21
问题 I have a pretty heavyweight query on the server that results in a new page render, and I'd like to pass along some of the results of the query to the client (as a javascript array of objects). This is basically so I don't have to do a separate JSON query later to get the same content (which is mostly static). The data will be useful eventually, but not initially so I didn't put it directly into the document. app.get('/expensiveCall', function(req, res) { // do expensive call var data =

Accessing Express.js local variables in client side JavaScript

瘦欲@ 提交于 2019-11-26 18:28:44
Curious if I'm doing this right and if not how you guys would approach this. I have a Jade template that needs to render some data retrieved from a MongoDB database and I also need to have access to that data inside a client side JavaScript file. I'm using Express.js and sending the data to the Jade template as follows : var myMongoDbObject = {name : 'stephen'}; res.render('home', { locals: { data : myMongoDbObject } }); Then inside of home.jade I can do things like : p Hello #{data.name}! Which writes out : Hello stephen! Now what I want is to also have access to this data object inside a

Passing an object with circular references from server to client-side Javascript while retaining circularity

余生长醉 提交于 2019-11-26 18:28:13
问题 I'm trying to pass an object with circular references from node.js server to client-side javascript. Server (node.js): var object = { circular: object } //.... app.get('/', function(req, res){ res.render('index.jade', {object: object}); }); Client-side Jade/Javascript script var object = !{JSON.stringify(object)}; Here I get the error that object contains circular references. Any way to get the object in client-side javascript, with or without circular references? 回答1: Douglas Crockford has a