Created
December 13, 2012 15:12
-
-
Save jrmoran/4277025 to your computer and use it in GitHub Desktop.
AngularJS and Express, rendering ejs-locals partials
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>About</h1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Index</h1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To pass messages, you can use the flash module for expressjs