--@angularJS--the more complex interaction demo2 between instruction and controller

Source: Internet
Author: User

1, index.html:

<! DOCTYPE html>
    <title>custom-directive </title>
    <meta charset= "Utf-8" >    
    < Link rel= "stylesheet" href= ". /css/bootstrap.css "
    <script src=". /js/angular.js "></SCRIPT>
    <!--<script src=". /js/jquery-1.10.2.min.js.js "></SCRIPT>-->
<body>
<!-- The following is the DEMO2 that the instruction interacts with the controller. -->
<!--the principle of this demo is to assign the method to the property, in JS directly call the property is equal to call the method-->
<div ng-controller= "Myctrl";
     <loader loadattr= "LoadData ()" > Sliding load </loader>
</div>
<div ng-controller= " MyCtrl2 "
    <loader loadattr=" LoadData2 () "> Sliding load </loader>
</div>
<script src= "./directive-controller2.js" ></SCRIPT>
</body>

2, Directive-controller2.js:

var mymodule = angular.module ("App", []);

Mymodule.controller (' Myctrl ', [' $scope ', function ($scope) {
$scope. Loaddata=function () {
Console.log ("Loading ...");
}
}]);
Mymodule.controller (' MyCtrl2 ', [' $scope ', function ($scope) {
$scope. Loaddata2=function () {
Console.log ("Loading 222222 ...");
}
}]);

Mymodule.directive (' loader ', function () {
return {
Restrict: ' AE ',
Link:function (scope,element,attrs) {
Element.bind (' MouseEnter ', function (event) {
Scope. $apply (attrs.loadattr);//The invocation of a method in a property does not have to be written like this, note that the property call must be lowercase, or invalid, regardless of whether the attribute in the HTML is uppercase or lowercase
})
}
}
});

[email protected] the more complex interaction between the instruction and the controller Demo2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.