This example mainly shows the use of controller and link parameters. And the case that multiple instructions work simultaneously.
1 <!DOCTYPE HTML>2 <HTMLNg-app= "MyModule">3 <HeadLang= "en">4 <MetaCharSet= "UTF-8">5 <title></title>6 </Head>7 <Body>8 <Div>9 <Div>Ten <SupermanStrength>Dynamic Superman---Power</Superman> One </Div> A <Div> - <SupermanStrength Speed>Motion Superman---Power + speed</Superman> - </Div> the <Div> - <SupermanStrength Speed Light>Motion Superman---Power + speed + Glow</Superman> - </Div> - </Div> + - </Body> + <Scripttype= "Text/javascript"src=".. /js/angular1.4.3.js "></Script> A <Scripttype= "Text/javascript"> at varMyModule=Angular.module ("MyModule",[]); - mymodule.directive ("Superman", function () { - return{ - scope:{}, - Restrict:"AE", - Controller:function($scope) { in $scope. Abilities=[]; - This. Addstrength= function () { to $scope. Abilities.push ("Strength"); + }; - This. Addspeed= function () { the $scope. Abilities.push (" Speed"); * }; $ This. Addlight= function () {Panax Notoginseng $scope. Abilities.push (' Light'); - }; the }, + Link:function(scope,element,attrs) { A Element.bind ("MouseEnter", function () { the Console.log (scope.abilities); + }) - } $ } $ }); - mymodule.directive ("Strength", function () { - return{ the require:"^superman", - Link:function(scope, element, Attrs, Supermanctrl) {Wuyi supermanctrl.addstrength (); the } - } Wu }); - mymodule.directive (" Speed", function () { About return{ $ require:"^superman", - Link:function(scope, element, Attrs, Supermanctrl) { - supermanctrl.addspeed (); - } A }; + }); the mymodule.directive (" Light", function () { - return{ $ require:"^superman", the Link:function(Scope,element,attrs,supermanctrl) { the supermanctrl.addlight (); the } the } - }) in </Script> the </HTML>
Angularjs to write multiple instructions