-
-
Save MBehtemam/54469653de73a8b04e09 to your computer and use it in GitHub Desktop.
This file contains 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
(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