"Instructions are defined as instructions for reuse!" ”
Instructions must be used in different controllers, in order to use it in different controllers, we must give the specified configuration item an instruction. This allows you to interact with the outside controller.
Examples are as follows:
Html:
<div ng-controller="myctrl"> howtoload="loaddata () "> Sliding load </loader> </div> <div ng-controller="MyCtrl2 "> howtoload="loadData2 ()"> Sliding load 2</ Loader> </div>
Js:
varApp = Angular.module ('MyModule', []); App.controller ('Myctrl', ['$scope', Function ($scope) {$scope. LoadData=function () {Console.log ("load data in ..."); }}]); App.controller ('MyCtrl2', ['$scope', Function ($scope) {$scope. LoadData2=function () {Console.log ("load data in ... 2222"); }}]); App.directive ("Loader", function () {return{restrict:"AE", Link:function (scope,element,attrs) {/*The link function has 4 parameters, the last parent controller, which uses 3*/Element.bind ('MouseEnter', function () {//scope. $apply ("LoadData ()"); //Notice the pits here, Howtoload will be converted to lowercase howtoload.scope. $apply (attrs.howtoload); }); } }});
Angular directive instructions for reuse