Skip to content

Instantly share code, notes, and snippets.

@heidsoft
Created December 20, 2016 04:17
Show Gist options
  • Select an option

  • Save heidsoft/e437061948ccad9e41f00f4acc59413e to your computer and use it in GitHub Desktop.

Select an option

Save heidsoft/e437061948ccad9e41f00f4acc59413e to your computer and use it in GitHub Desktop.
.directive('repeater', function ($document) {
return {
restrict: 'A',
scope: { colors: "=myColor" },//隔离作用域,使用双向绑定颜色
controller: function( $scope, $element, $attrs, $transclude ) {
console.log( $attrs.repeater + ' (controller)' );
},
compile: function(element, attrs) {
console.log("test repeater....");
console.log(element);
var template = angular.element(element).children().clone();
console.log(template);
for(var i=0; i<attrs.repeater - 1; i++) {
angular.element(element).append(template.clone());
}
console.log( attrs.repeater + ' (compile)' );
return {
pre: function preLink( scope, element, attributes ) {
console.log( attributes.repeater + ' (pre-link)' );
},
post: function postLink( scope, element, attributes ) {
//这里写业务逻辑最安全
console.log( attributes.repeater + ' (post-link)' );
}
};
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment