Skip to content

Instantly share code, notes, and snippets.

@samuelsmal
Last active January 13, 2016 16:02
Show Gist options
  • Save samuelsmal/32541b8ebc0b56f01cf8 to your computer and use it in GitHub Desktop.
Save samuelsmal/32541b8ebc0b56f01cf8 to your computer and use it in GitHub Desktop.
Angular partial directive (Rails partial equivalent)
/* global angular: false */
;(function () {
'use strict'
/**
* sam-partial directive
*
* This is simple *partial* directive. It functions the same as `ng-include`
* but instead of nesting it replaces the element.
*
* Usage:
* <sam-partial src="/smaller/component/to/include.html"></sam-partial>
*/
angular
.module('sam.utils')
.directive('samPartial', partial)
function partial () {
return {
replace: true,
templateUrl: function (elem, attrs) {
if (!attrs.src) {
throw new Error('samPartial: no src given')
}
return attrs.src
}
}
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment