Skip to content

Instantly share code, notes, and snippets.

@MBehtemam
Forked from thgreasi/gen.genericDirectives.js
Created August 17, 2014 08:07
Show Gist options
  • Save MBehtemam/54469653de73a8b04e09 to your computer and use it in GitHub Desktop.
Save MBehtemam/54469653de73a8b04e09 to your computer and use it in GitHub Desktop.
(function() {
"use strict";
angular.module('gen.genericDirectives', [])
.directive('genDynamicDirective', ['$compile',
function($compile) {
return {
restrict: "E",
require: '^ngModel',
scope: true,
link: function(scope, element, attrs, ngModel) {
var ngModelItem = scope.$eval(attrs.ngModel);
scope.ngModelItem = ngModelItem;
var getView = scope.$eval(attrs.genGetDynamicView);
if (getView && typeof getView === 'function') {
var templateUrl = getView(ngModelItem);
if (templateUrl) {
element.html('<div ng-include src="\'' + templateUrl + '\'"></div>');
}
$compile(element.contents())(scope);
}
}
};
}
]);
})();
// function getView (ngModelItem) {
// var template = '';
// switch (ngModelItem.Type) {
// case 'Type1':
// template = 'Type1.html';
// break;
// case 'Type2':
// template = 'Type2.html';
// break;
// }
// return template;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment