This article describes the copy instruction implementation method of AngularJS custom instruction. Share it for your reference, as follows:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="" rel="external nofollow" > <script src=""></script> <script src=""></script> <script src=""></script> <script type="text/javascript"> var app = ('myapp', []); ('duplicate', function($rootScope){ return { transclude: 'element', replace: true, priority: 2, link: function(scope, elem, attrs, ctrl, transclude) { var times = parseInt(); var previous = elem; var childScope; for(var i = 0; i < times; i++) { childScope = scope.$new();// Create a new scope's subscope = i; transclude(childScope, function(clone){//transclude associates each childScope with clone, one by one (one pair) // (childScope.$id); // (().$id) (clone);//Split previous and clone and then assign value to clone previous = clone; }); } ();//You can see that 5 subs () are all scope; (scope == $rootScope)// You can see that the command scope is $rootScope because scope:false }, } }); </script> </head> <body ng-app="myapp"> <input type='text' ng-model='number' duplicate="5" /> <br/> <!--Bind with above --> <input type="text" ng-model=""/><br/><inputtype="text"ng−model="" /> </body> </html>
For more information about AngularJS, readers who are interested in view the topic of this site:Summary of AngularJS command operation skills》、《AngularJS Introduction and Advanced Tutorial"and"AngularJS MVC architecture summary》
I hope this article will be helpful to everyone's AngularJS programming.