Skip to content

Instantly share code, notes, and snippets.

@think2011
Created May 8, 2014 03:39
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 think2011/696746b70d3a4bc70f40 to your computer and use it in GitHub Desktop.
Save think2011/696746b70d3a4bc70f40 to your computer and use it in GitHub Desktop.
angularjs,这是一个 scope 中带有 html 代码的处理方式。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div test ng-bind-html="title"></div>
<script>
app.directive('test', function ($sce) {
return {
restrict: 'A',
link: function (scope) {
scope.title = '<h1>大标题</h1>';
scope.toTrusted = function(html) {
return $sce.trustAsHtml(html);
};
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment