Last active
August 29, 2015 14:05
-
-
Save ilguzin/97a153c18a01b64f6541 to your computer and use it in GitHub Desktop.
How to load script inside AngularJS partial. Note [SCRIPT_PATH] in example.html
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
<script type="text/javascript" data-ng-script-load> | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = '[SCRIPT_PATH]'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
</script> |
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
define ["angular"], (angular) -> | |
'use strict' | |
ngScriptLoad = () -> | |
restrict: "E" | |
scope: false | |
link: (scope, elem, attr) -> | |
if angular.isDefined(attr.ngScriptLoad) | |
code = elem.text() | |
f = new Function(code) | |
f() | |
return | |
[ngScriptLoad] |
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
define [ | |
"angular" | |
"./directives/ngScriptLoadDirective" | |
], ( | |
angular, | |
ngScriptLoad, | |
) -> | |
"use strict" | |
angular.module("smapp.main", []) | |
.directive("script", ngScriptLoad) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment