return {
restrict: 'A',
scope: {
message: '=mainMessage',
typeMessage: '=typeMessage'
},
templateUrl: function(elem, attrs) {
return 'template/common/' + attrs.typeMessage + '-message.tpl.html';
},
link: function(scope, element, attrs) {
}
<div class="mess" main-message="message" type-message="message.type"
ng-repeat="message in messages track by message.id">
</div>
return {
template: '<ng-include src="getTemplateUrl()"/>',
scope: {
message: '=mainMessage',
typeMessage: '=typeMessage'
},
restrict: 'A',
controller: function($scope) {
$scope.getTemplateUrl = function() {
return 'template/common/' + $scope.typeMessage + "-message.tpl.html";
}
},
link: function(scope, element, attrs) {
}
}
// тут можете сгенерировать любой вид директивы:
function getForm( obj, настройки){
str = '<a title="открыть в новом окне" ng-href="contragents.admin.html#нси_ключ={{obj._source.нси_ключ}}" target="_blank" ng-show="obj._source._$editor_props.menu_type==1" class="btn btn-xs btn-primary"><span ng-show="obj._source._$editor_props.bool_change==true" class="glyphicon glyphicon-asterisk" style="color:rgb(255, 183, 100)"></span> <u>'+obj._index+'-'+obj._type+'</u> <sup><i class="fa fa-external-link"></i></sup> </a>';
return str;
}
return {
scope: { ... },
// templateUrl: - убираем вообще
link: function(scope, element, attrs) {
var str_template = getForm(scope.obj, scope.настройки );
// надеюсь это не сложно:
var dom_node = $compile(str_template)(scope);
element.append(dom_node);
}
};
App.controller('formCtrl', ['$scope', function ($scope) {
$scope.order = {
md5hash:"036e4ab264;3253465a34535234524635f353",
name:'Введите имя',
phone:'Укажите свой номер',
email:'Ваш почтовый ящик',
address:""
};
}]).directive('formorder', [function() {
return {
templateUrl: 'tpl/formOrder.html',
replace: true,
scope:{
},
link: function ($scope, $element, $attrs){
$scope.order = $scope.$parent.order;
}
}
}]);