码迷,mamicode.com
首页 > Web开发 > 详细

angularjs 指令间相互调用

时间:2017-05-28 11:45:55      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:调用   log   require   click   ddl   directive   .sh   lin   addclass   

<div ng-app="app">
    <div ng-controller="myctl">
       
        <button superman strength>按钮1111</button>
        <button superman strength speed>按钮22222</button>
    </div>
</div>
<script>
    var app = angular.module("app", []);
    app.controller("myctl", function ($scope) {
        $scope.info = "";
        $scope.showinfo = function () {
            $scope.info = "loading.....";
        };
    });

    app.directive("superman", function () {
        return {
            scope: {},
            controller: function ($scope) {
                $scope.arr = [];

                this.addL = function () { $scope.arr.push("length") };
                this.addS = function () { $scope.arr.push("speed") };
            },
            link: function (scope, element, attrs) {
                element.addClass("btn btn-success");
                element.on("click", function () {
                    alert(scope.arr);
                });
            }
        }
    });
    app.directive("strength", function () {
        return {
            require:^superman,
            link: function (scope, element, attrs, ctl) {
                ctl.addL();
            }
        }
    });
    app.directive("speed", function () {
        return {
            require: ^superman,
            link: function (scope, element, attrs, ctl) {
                ctl.addS();
            }
        }
    });

</script>

 

angularjs 指令间相互调用

标签:调用   log   require   click   ddl   directive   .sh   lin   addclass   

原文地址:http://www.cnblogs.com/lunawzh/p/6915212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!