标签:angularjs diretive angularjs directive 指令复制 指令克隆
tw.factory('DirectiveUtil', [function() { var DirectiveUtil = {}; DirectiveUtil.DirectiveBuilder = function(directiveName) { directive = directiveName; directiveBuffer = '<' + directiveName + ' '; this.setDirectiveName = function(directiveName) { directive = directiveName; directiveBuffer = '<' + directiveName + ' '; } this.getDirectiveName = function() { return directive; } // name: directive中scope的name, value: clone directive操作时,数据绑定的名称 this.appendAttr = function(name, value) { directiveBuffer += name + '=\'' + value + '\' '; return this; } this.build = function(compile, scope) { return compile(directiveBuffer + ' />')(scope); } }; return DirectiveUtil; }]);
var dirctBuilder = new DirectiveUtil.DirectiveBuilder('tw-contact-form'); dirctBuilder.appendAttr('is-new', 'isNew') // $scope.isNew, $scope.showAddBtn, $scope.initData .appendAttr('show-add-btn', 'showAddBtn') .appendAttr('init-data', 'initData'); var li = $('<li></li>').attr('id', 'ContactList' + len); li.append(dirctBuilder.build($compile, $scope));
AngularJS clone directive 指令复制
标签:angularjs diretive angularjs directive 指令复制 指令克隆
原文地址:http://blog.csdn.net/hai8902882/article/details/42061307