Skip to content

Instantly share code, notes, and snippets.

@yoren
Last active August 29, 2015 14:09
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 yoren/56da3883bcdb0a8f2e6b to your computer and use it in GitHub Desktop.
Save yoren/56da3883bcdb0a8f2e6b to your computer and use it in GitHub Desktop.
Best Practice to sanitize HTML in AngularJS
<h1>{{post.title}}</h1>
<div ng-bind-html="post.content"></div>
<?php
function my_scripts() {
wp_register_script(
'angularjs',
get_stylesheet_directory_uri() . '/bower_components/angular/angular.min.js'
);
wp_register_script(
'angularjs-route',
get_stylesheet_directory_uri() . '/bower_components/angular-route/angular-route.min.js'
);
wp_register_script(
'angularjs-sanitize',
get_stylesheet_directory_uri() . '/bower_components/angular-sanitize/angular-sanitize.min.js'
);
wp_enqueue_script(
'my-scripts',
get_stylesheet_directory_uri() . '/js/scripts.js',
array( 'angularjs', 'angularjs-route', 'angularjs-sanitize' )
);
wp_localize_script(
'my-scripts',
'myLocalized',
array(
'partials' => trailingslashit( get_template_directory_uri() ) . 'partials/'
)
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
angular.module('app', ['ngRoute', 'ngSanitize'])
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment