Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 13, 2012 15:12
Show Gist options
  • Save jrmoran/4277025 to your computer and use it in GitHub Desktop.
Save jrmoran/4277025 to your computer and use it in GitHub Desktop.
AngularJS and Express, rendering ejs-locals partials
var app = angular.module('app', ['ngResource']);
app.config(function($locationProvider, $routeProvider) {
// $locationProvider.html5Mode(true);
$routeProvider
.when('/', { templateUrl: 'partials/index', controller: 'ctrl' })
.when('/about', { templateUrl: 'partials/about', controller: 'ctrl' })
.otherwise({redirectTo:'/'});
});
app.controller('ctrl', function($scope){});
exports.index = (req, res)->
res.render 'index', message:"Hello!!!"
exports.partials = (req, res)->
filename = req.params.filename
return unless filename # might want to change this
res.render "partials/#{filename}"
express = require 'express'
routes = require './routes'
engine = require 'ejs-locals'
app = express()
app.engine('ejs', engine)
app.set('view engine', 'ejs')
app.set('views', __dirname + '/views')
app.use(express.static __dirname + '/public')
app.get('/partials/:filename', routes.partials)
app.use(routes.index) # everything else
app.listen 3000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Test</title>
<script src="components/angular-complete/angular.js"
type="text/javascript"></script>
<script src="components/angular-complete/angular-resource.js"
type="text/javascript"></script>
<script src="app.js"
type="text/javascript"></script>
</head>
<body ng-app='app'>
<%- message %>
<a href="#/about"> /about</a> |
<a href="#/"> home</a>
<!-- uncomment if HTML5Mode on -->
<!-- <a href="/about"> /about</a> | -->
<!-- <a href="/"> home</a> -->
<hr />
<div ng-view></div>
</body>
</html>
@kimyongin
Copy link

use ajax

@watat83
Copy link

watat83 commented Jul 5, 2016

To pass messages, you can use the flash module for expressjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment