zoukankan      html  css  js  c++  java
  • angularJS自定义指令间的“沟通”

    由此例子我们可以看出,angularJS使用指令时link的执行顺序
    <
    html> <head> <meta charset="utf-8"/> <title></title> </head> <body ng-app="components"> <div> <name xm> <h1>小明</h1> </name> </div> <div> <name xm xmxh> <h1>小明,小花</h1> </name> </div> <div> <name xm xmxh xmxhxl> <h1>小明,小花,小龙</h1> </name> </div> </body> <script src="angular.js"></script> <script> var app= angular.module('components', []); app.directive("name",function(){ return { restrict: "AE", scope:{}, controller:function($scope){ $scope.name=[]; this.Xm=function(){ $scope.name.push("小明"); }; this.Xh=function(){ $scope.name.push("小花"); } this.Xl=function(){ $scope.name.push("小龙"); } },//controller中定义的方法和乘员可以通过link的第四个参数实现对外公布 link:function(scope, element, attr, superCtrl){ element.bind("click",function(){ alert(scope.name); }); } } }); app.directive("xm",function(){ return { require:"^name", link:function(scope, element, attr, superCtrl){ superCtrl.Xm(); } } }); app.directive("xmxh",function(){ return { require:"^name", link:function(scope, element, attr, superCtrl){ superCtrl.Xh(); } } }); app.directive("xmxhxl",function(){ return { require:"^name", link:function(scope, element, attr, superCtrl){ superCtrl.Xl(); } } }); </script> </html>
  • 相关阅读:
    zabbix系列 ~ mongo监控相关
    zabbix系列 ~ 自动监控多实例功能
    mysql 查询优化 ~ 多表查询改写思路
    MGR架构~高可用架构细节的梳理
    mysql 半同步复制~ 整体概述与改进
    android 单独编译某个模块
    Nginx使用
    21天学通C++学习笔记(九):类和对象
    1. 个人经验总结
    C++视频教程学习笔记
  • 原文地址:https://www.cnblogs.com/zzq-include/p/4492080.html
Copyright © 2011-2022 走看看