--@angularJS--interaction between the instruction and the Controller demo

Source: Internet
Author: User

1, index.html:

<! DOCTYPE html>
<meta charset= "Utf-8" >
<link rel= "stylesheet" href= ". /css/bootstrap.css ">
<script src= ". /js/angular.js "></script>
<!--The following is a demo of the instructions interacting with the controller. -
<div ng-controller= "Myctrl" >
<loader> Sliding Loading </loader>
<script src= "./directive-controller.js" ></script>

2, Directive-controller.js:

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

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

Mymodule.directive (' loader ', function () {
return {
Restrict: ' AE ',
transclude:true,//This is also a pit, declaring the above substitution and this nested property without declaring the template substitution and nesting, the light in the HTML to write a custom directive label will not come out of anything
scope:{},//this is a pit. When the controller interacts with the instruction cannot declare the independent scope, otherwise the scope becomes private, the instruction will not see the method defined in the controller, the program error: said that the private scope cannot find the LoadData method
Link:function (scope,element,attrs) {
Element.bind (' MouseEnter ', function (event) {
Scope. $apply ("LoadData ()");
Scope.loaddata ();

[email protected] interaction between command and Controller demo

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.