Created
December 20, 2016 04:17
-
-
Save heidsoft/e437061948ccad9e41f00f4acc59413e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| .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