Skip to content

Instantly share code, notes, and snippets.

@danielpsf
Created January 9, 2014 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpsf/8333968 to your computer and use it in GitHub Desktop.
Save danielpsf/8333968 to your computer and use it in GitHub Desktop.
This is a really simple way to get a formatted string from the database and put it into front end with AngularJS. You can see it working here: https://gist.github.com/danielpsf/8333968
<!DOCTYPE html>
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app="myApp" ng-controller="myController">
<div my-directive>
</div>
</body>
</html>
var myApp = angular.module('myApp', []);
myApp.controller('myController', ['$scope', function($scope) {
$scope.myTemplateStr = '<p>My name is <strong>Daniel</strong></p>';
}]);
myApp.directive('myDirective', [function() {
return function(scope, element, attrs) {
element.html(scope.myTemplateStr);
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment