Last active
January 13, 2016 16:02
-
-
Save samuelsmal/32541b8ebc0b56f01cf8 to your computer and use it in GitHub Desktop.
Angular partial directive (Rails partial equivalent)
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
/* 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