Created
September 4, 2014 01:30
-
-
Save pmanijak/c8c391d16319b2d31a43 to your computer and use it in GitHub Desktop.
Using Angular ng-model with server-side templates
This file contains hidden or 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
<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