Skip to content

Instantly share code, notes, and snippets.

@pmanijak
Created September 4, 2014 01:30
Show Gist options
  • Save pmanijak/c8c391d16319b2d31a43 to your computer and use it in GitHub Desktop.
Save pmanijak/c8c391d16319b2d31a43 to your computer and use it in GitHub Desktop.
Using Angular ng-model with server-side templates
<html ng-app="project">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script>
// Create your module
var dependencies = [];
var app = angular.module('project', dependencies);
// Create a 'defaults' service
app.value("defaults", /* your server-side JSON here */);
// e.g. { whatever: 'some default text' }
// Create a controller that uses the service
app.controller('PageController', function(defaults, $scope) {
// Populate your model with the service
$scope.model = defaults;
});
</script>
<body>
<div ng-controller="PageController">
<!-- Bind with the standard ng-model approach -->
<input type="text" ng-model="model.whatever">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment